You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Previously, when mapping primitive collections or owned types to JSON in the database, the SQL Server provider stored the JSON data in an `nvarchar(max)` column:
39
+
40
+
```c#
41
+
publicclassBlog
42
+
{
43
+
// ...
44
+
45
+
// Primitive collection, mapped to nvarchar(max) JSON column
46
+
publicstring[] Tags { get; set; }
47
+
// Owned entity type mapped to nvarchar(max) JSON column
For the above, EF previously generated the following table:
58
+
59
+
```sql
60
+
CREATE TABLE [Blogs] (
61
+
...
62
+
[Tags] nvarchar(max),
63
+
[Posts] nvarchar(max)
64
+
);
65
+
```
66
+
67
+
#### New behavior
68
+
69
+
With EF 10, if you configure EF with <xref:Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseAzureSql*> ([see documentation](xref:core/providers/sql-server/index#usage-and-configuration)), or configure EF with a compatibility level of 170 or above ([see documentation](xref:core/providers/sql-server/index#compatibility-level)), EF will map to the new JSON data type instead:
70
+
71
+
```sql
72
+
CREATE TABLE [Blogs] (
73
+
...
74
+
[Tags] json
75
+
[Posts] json
76
+
);
77
+
```
78
+
79
+
Note that if you have an existing table and are using <xref:Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseAzureSql*>, upgrading to EF 10 will cause a migration to be generated which alters all existing `nvarchar(max)` JSON columns to `json`. This alter operation is supported and should get applied seamlessly and without any issues, but is a non-trivial change to your database.
80
+
81
+
> [!NOTE]
82
+
> For 10.0.0 rc1, support for the new JSON data type has been temporarily disabled for Azure SQL Database, due to lacking support. These issues are expected to be resolved by the time EF 10.0 is released, and the JSON data type will become the default until then.
83
+
84
+
#### Why
85
+
86
+
The new JSON data type introduced by SQL Server is a superior, 1st-class way to store and interact with JSON data in the database; it notably brings significant performance improvements ([see documentation](/sql/t-sql/data-types/json-data-type)). All applications using Azure SQL Database or SQL Server 2025 are encouraged to migrate to the new JSON data type.
87
+
88
+
#### Mitigations
89
+
90
+
If you do not wish to transition to the new JSON data type right away, you can configure EF with a compatibility level lower than 170:
Note that if your EF application already uses JSON via `nvarchar` columns, these columns will be automatically changed to `json` with the first migration. You can opt out of this by manually setting the column type to `nvarchar(max)`, or configuring a compatibility level lower than 170.
120
120
121
+
> [!NOTE]
122
+
> For 10.0.0 rc1, support for the new JSON data type has been temporarily disabled for Azure SQL Database, due to lacking support. These issues are expected to be resolved by the time EF 10.0 is released, and the JSON data type will become the default until then.
0 commit comments