Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions entity-framework/core/what-is-new/ef-core-11.0/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -85,6 +86,39 @@ No code changes are required beyond adding this package reference. If you use `S

## Low-impact changes

<a name="sqlserver-compatibility-level-160"></a>

### SQL Server compatibility level now defaults to 160

[Tracking Issue #38198](https://github.com/dotnet/efcore/issues/38198)
Comment thread
roji marked this conversation as resolved.

#### Old behavior

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.

#### New behavior

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.

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("<connection string>", o => o.UseCompatibilityLevel(150));
Comment thread
roji marked this conversation as resolved.
}
```

For more information, see the [SQL Server compatibility level documentation](xref:core/providers/sql-server/index#compatibility-level).

<a name="migrations-not-found"></a>

### EF Core now throws by default when no migrations are found
Expand Down
4 changes: 4 additions & 0 deletions entity-framework/core/what-is-new/ef-core-11.0/whatsnew.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

* <xref:Microsoft.EntityFrameworkCore.SqlServerDbContextOptionsExtensions.UseSqlServer*> 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

<a name="cosmos-complex-types"></a>
Expand Down
Loading