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 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.
98
+
99
+
#### New behavior
100
+
101
+
Starting with EF Core 11.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.
102
+
103
+
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.
104
+
105
+
#### Why
106
+
107
+
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.
108
+
109
+
#### Mitigations
110
+
111
+
If your database does not support compatibility level 160, configure EF Core to use the compatibility level supported by your database:
Copy file name to clipboardExpand all lines: entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md
+17Lines changed: 17 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -262,6 +262,23 @@ For the full `JSON_PATH_EXISTS` SQL Server documentation, see [`JSON_PATH_EXISTS
262
262
263
263
## SQL Server
264
264
265
+
<aname="sql-server-compatibility-level-160"></a>
266
+
267
+
### Default compatibility level changed to SQL Server 2022
268
+
269
+
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.
270
+
271
+
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`:
272
+
273
+
```sql
274
+
SELECT [c].[CustomerID], [c].[ContactName]
275
+
FROM [Customers] AS [c]
276
+
ORDER BY [c].[ContactTitle], [c].[ContactName]
277
+
OFFSET @p ROWS FETCH NEXT LEAST(@p1, @p2) ROWS ONLY
278
+
```
279
+
280
+
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-11.0/breaking-changes#sqlserver-compatibility-level-160) and the [SQL Server provider documentation](xref:core/providers/sql-server/index#compatibility-level).
0 commit comments