diff --git a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md index ece54855f2..ca5a3a781b 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md @@ -23,6 +23,7 @@ This page documents API and behavior changes that have the potential to break ex |:--------------------------------------------------------------------------------------------------------------- | -----------| | [Sync I/O via the Azure Cosmos DB provider has been fully removed](#cosmos-nosync) | Medium | | [Microsoft.Data.SqlClient has been updated to 7.0](#sqlclient-7) | Medium | +| [SQL Server compatibility level now defaults to 160](#sqlserver-compatibility-level-160) | Low | | [EF Core now throws by default when no migrations are found](#migrations-not-found) | Low | | [`EFOptimizeContext` MSBuild property has been removed](#ef-optimize-context-removed) | Low | | [EF tools packages no longer reference Microsoft.EntityFrameworkCore.Design](#ef-tools-no-design-dep) | Low | @@ -85,6 +86,39 @@ No code changes are required beyond adding this package reference. If you use `S ## Low-impact changes + + +### SQL Server compatibility level now defaults to 160 + +[Tracking Issue #38198](https://github.com/dotnet/efcore/issues/38198) + +#### Old behavior + +Previously, when using without explicitly configuring a SQL Server compatibility level, EF Core defaulted to compatibility level 150, corresponding to SQL Server 2019. + +#### New behavior + +Starting with EF Core 11.0, 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`, , , and some `Take`/`Skip` patterns. + +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. + +#### Why + +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. + +#### Mitigations + +If your database does not support compatibility level 160, configure EF Core to use the compatibility level supported by your database: + +```csharp +protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +{ + optionsBuilder.UseSqlServer("", o => o.UseCompatibilityLevel(150)); +} +``` + +For more information, see the [SQL Server compatibility level documentation](xref:core/providers/sql-server/index#compatibility-level). + ### EF Core now throws by default when no migrations are found diff --git a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md index 97fe797b3b..fe032c5c8a 100644 --- a/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md +++ b/entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md @@ -500,6 +500,10 @@ In addition, `EF.Functions.DateTrunc()` is now available for truncating `DateTim For the complete list of date/time function translations, see the [SQL Server function mappings page](xref:core/providers/sql-server/functions). +### Other changes + +* now defaults to compatibility level 160 (SQL Server 2022), enabling SQL Server 2022-specific translations such as `LEAST` and `GREATEST` by default; see the [breaking change note](xref:core/what-is-new/ef-core-11.0/breaking-changes#sqlserver-compatibility-level-160) for more information. + ## Cosmos DB