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
|[EF tools now require framework to be specified for multi-targeted projects](#ef-tools-multi-targeting)| Medium |
26
26
|[Application Name is now injected into the connection string](#sqlserver-application-name)| Low |
27
+
|[SQL Server compatibility level now defaults to 160](#sqlserver-compatibility-level-160)| Low |
27
28
|[SQL Server json data type used by default on Azure SQL and compatibility level 170](#sqlserver-json-data-type)| Low |
28
29
|[Parameterized collections now use multiple parameters by default](#parameterized-collections)| Low |
29
30
|[ExecuteUpdateAsync now accepts a regular, non-expression lambda](#ExecuteUpdateAsync-lambda)| Low |
@@ -96,6 +97,39 @@ When a connection string without an `Application Name` is passed to EF, EF now i
96
97
97
98
A mitigation is to simply define an `Application Name` in your connection string. Once one is defined, EF does not overwrite it and the original connection string is preserved exactly as-is.
98
99
100
+
<aname="sqlserver-compatibility-level-160"></a>
101
+
102
+
### SQL Server compatibility level now defaults to 160
Previously, when using <xref:Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer*> without explicitly configuring a SQL Server compatibility level, EF Core defaulted to compatibility level 150, corresponding to SQL Server 2019.
109
+
110
+
#### New behavior
111
+
112
+
Starting with EF Core 10.0, <xref:Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer*> defaults to compatibility level 160, corresponding to SQL Server 2022. This allows EF to generate SQL which uses SQL Server 2022 features by default. For example, some queries now use `LEAST` and `GREATEST`, including translations for `Math.Min`, `Math.Max`, <xref:Microsoft.EntityFrameworkCore.RelationalDbFunctionsExtensions.Least*>, <xref:Microsoft.EntityFrameworkCore.RelationalDbFunctionsExtensions.Greatest*>, and some `Take`/`Skip` patterns.
113
+
114
+
If your database runs on SQL Server 2019 or older, or is configured with a compatibility level lower than 160, some SQL generated by EF Core may no longer be supported by the database.
115
+
116
+
#### Why
117
+
118
+
SQL Server 2022 has been available for several years, and using compatibility level 160 by default allows EF Core to generate simpler and more efficient SQL for newer SQL Server versions.
119
+
120
+
#### Mitigations
121
+
122
+
If your database does not support compatibility level 160, configure EF Core to use the compatibility level supported by your database:
If you're targeting on-premises SQL Server, the default compatibility level with `UseSqlServer` is currently 150 (SQL Server 2019), so the JSON data type is not used.
201
+
If you're targeting on-premises SQL Server, the default compatibility level with `UseSqlServer` is currently 160 (SQL Server 2022), so the JSON data type is not used.
168
202
169
203
As an alternative, you can explicitly set the column type on specific properties to be `nvarchar(max)`:
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.
124
124
125
+
<aname="sql-server-compatibility-level-160"></a>
126
+
127
+
### Default compatibility level changed to SQL Server 2022
128
+
129
+
When using <xref:Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer*> without explicitly configuring a SQL Server compatibility level, EF Core now defaults to compatibility level 160 (SQL Server 2022), rather than 150 (SQL Server 2019). This enables SQL Server 2022-specific SQL translations by default.
130
+
131
+
For example, `Math.Min`, `Math.Max`, <xref:Microsoft.EntityFrameworkCore.RelationalDbFunctionsExtensions.Least*>, <xref:Microsoft.EntityFrameworkCore.RelationalDbFunctionsExtensions.Greatest*>, and `Min`/`Max` over inline or primitive collections can now translate to `LEAST` and `GREATEST` by default. EF can also use `LEAST` to simplify some queries with multiple `Take` operators, or with `Skip` and `Take`:
132
+
133
+
```sql
134
+
SELECT [c].[CustomerID], [c].[ContactName]
135
+
FROM [Customers] AS [c]
136
+
ORDER BY [c].[ContactTitle], [c].[ContactName]
137
+
OFFSET @p ROWS FETCH NEXT LEAST(@p1, @p2) ROWS ONLY
138
+
```
139
+
140
+
If your database is SQL Server 2019 or older, or has a compatibility level lower than 160, configure EF's SQL Server compatibility level explicitly. For more information, see the [breaking change note](xref:core/what-is-new/ef-core-10.0/breaking-changes#sqlserver-compatibility-level-160) and the [SQL Server provider documentation](xref:core/providers/sql-server/index#compatibility-level).
0 commit comments