Skip to content

Bump default SQL Server compat level to 160 (SQL Server 2022)#38199

Open
roji wants to merge 2 commits intodotnet:mainfrom
roji:SqlServerCompatLevel
Open

Bump default SQL Server compat level to 160 (SQL Server 2022)#38199
roji wants to merge 2 commits intodotnet:mainfrom
roji:SqlServerCompatLevel

Conversation

@roji
Copy link
Copy Markdown
Member

@roji roji commented Apr 30, 2026

Aside from bumping the default compat level, this also cleans up SQL Server query tests, removing entire test suites which were dedicated to testing different versions of SQL Server. Now that we have reliable, constant testing of the different SQL Server versions in Github Actions, we can rely on CI for proper, multi-version coverage.

Aside from simplifying everything and keeping all the different SQL variants for different versions in a single place/test, this also removes cases where we duplicated an entire large test suite just because one test inside it needed to vary its SQL across versions.

Closes #38198

Copilot AI review requested due to automatic review settings April 30, 2026 07:06
@roji roji requested a review from a team as a code owner April 30, 2026 07:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates EF Core SQL Server provider defaults to align with SQL Server 2022 by bumping the default SQL Server compatibility level used by the provider.

Changes:

  • Bump SqlServerDefaultCompatibilityLevel from 150 (SQL Server 2019) to 160 (SQL Server 2022).
  • Update the inline compatibility-level reference comments in SqlServerOptionsExtension.

@roji roji marked this pull request as draft April 30, 2026 13:03
@roji roji force-pushed the SqlServerCompatLevel branch from 3513569 to 59306d8 Compare May 1, 2026 08:45
@roji roji force-pushed the SqlServerCompatLevel branch from 59306d8 to e7fed49 Compare May 1, 2026 08:46
@roji roji marked this pull request as ready for review May 1, 2026 11:40
Copilot AI review requested due to automatic review settings May 1, 2026 11:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates EF Core’s SQL Server provider default compatibility level to 160 (SQL Server 2022) and consolidates version-dependent SQL Server test coverage by branching on runtime server capabilities instead of maintaining separate per-version test suites.

Changes:

  • Bump default SQL Server compatibility level from 150 to 160.
  • Remove SQL Server 160-specific test suites and fold their assertions into the main SQL Server test classes via capability checks.
  • Configure key SQL Server test fixtures to set EF compatibility level from the current test server environment.

Reviewed changes

Copilot reviewed 26 out of 29 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
test/EFCore.SqlServer.FunctionalTests/Query/Translations/StringTranslationsSqlServerTest.cs Makes TrimStart/TrimEnd parameterized translations conditional on SQL Server 2022 function support; adds baselines for supported servers.
test/EFCore.SqlServer.FunctionalTests/Query/Translations/StringTranslationsSqlServer160Test.cs Removes dedicated SQL Server 160 test class (now covered via conditional logic).
test/EFCore.SqlServer.FunctionalTests/Query/Translations/MathTranslationsSqlServerTest.cs Enables LEAST/GREATEST translation baselines when SQL Server 2022 functions are supported; otherwise expects translation failure.
test/EFCore.SqlServer.FunctionalTests/Query/Translations/MathTranslationsSqlServer160Test.cs Removes dedicated SQL Server 160 math translation test class.
test/EFCore.SqlServer.FunctionalTests/Query/Translations/BasicTypesQuerySqlServerFixture.cs Sets compatibility level from environment for translation tests; removes the 160-specific fixture.
test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs Adds branching SQL baselines for JSON type support and SQL Server 2022 LEAST/GREATEST support; fixture sets compatibility from environment.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindStringIncludeQuerySqlServerTest.cs Updates baselines to branch on SQL Server 2022 function support (LEAST in TOP/FETCH).
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeQuerySqlServerTest.cs Updates split-include baselines to branch on SQL Server 2022 function support.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSplitIncludeNoTrackingQuerySqlServerTest.cs Updates split-include (no-tracking) baselines to branch on SQL Server 2022 function support.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindSelectQuerySqlServerTest.cs Updates baselines to branch on SQL Server 2022 function support (LEAST in TOP).
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindQuerySqlServerFixture.cs Sets compatibility level from environment for Northwind SQL Server test contexts.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindMiscellaneousQuerySqlServerTest.cs Updates several baselines to branch on SQL Server 2022 function support (LEAST usage).
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeQuerySqlServerTest.cs Updates include-query baselines to branch on SQL Server 2022 function support.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindIncludeNoTrackingQuerySqlServerTest.cs Updates include-query (no-tracking) baselines to branch on SQL Server 2022 function support.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindFunctionsQuerySqlServer160Test.cs Removes dedicated SQL Server 160 Northwind functions test suite.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindEFPropertyIncludeQuerySqlServerTest.cs Updates EF.Property include-query baselines to branch on SQL Server 2022 function support.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServerTest.cs Enables LEAST/GREATEST translation baselines when SQL Server 2022 functions are supported; otherwise expects translation failure.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindDbFunctionsQuerySqlServer160Test.cs Removes dedicated SQL Server 160 Northwind DbFunctions test suite.
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindCompiledQuerySqlServerTest.cs Branches baselines on JSON type support (JSON_VALUE RETURNING vs non-RETURNING).
test/EFCore.SqlServer.FunctionalTests/Query/NorthwindChangeTrackingQuerySqlServerTest.cs Updates baselines to branch on SQL Server 2022 function support (LEAST in TOP).
test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerTest.cs Branches baseline on SQL Server 2022 function support (GREATEST vs older pattern).
test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsSharedTypeQuerySqlServerFixture.cs Sets compatibility level from environment for shared-type complex navigation tests.
test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerTest.cs Branches baseline on SQL Server 2022 function support (GREATEST vs older pattern).
test/EFCore.SqlServer.FunctionalTests/Query/ComplexNavigationsQuerySqlServerFixture.cs Sets compatibility level from environment for complex navigation tests.
src/EFCore.SqlServer/Infrastructure/SqlServerDbContextOptionsBuilder.cs Updates public API docs to reflect default compatibility level 160.
src/EFCore.SqlServer/Infrastructure/Internal/SqlServerOptionsExtension.cs Updates provider default compatibility level constant to 160 and refreshes compatibility-level reference comment.

=> SqlServerNorthwindTestStoreFactory.Instance;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> TestEnvironment.SetCompatibilityLevelFromEnvironment(base.AddOptions(builder));
=> SqlServerTestStoreFactory.Instance;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> TestEnvironment.SetCompatibilityLevelFromEnvironment(base.AddOptions(builder));
Comment on lines +13 to +14
public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> TestEnvironment.SetCompatibilityLevelFromEnvironment(base.AddOptions(builder));
=> SqlServerTestStoreFactory.Instance;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> TestEnvironment.SetCompatibilityLevelFromEnvironment(base.AddOptions(builder));
=> (TestSqlLoggerFactory)ListLoggerFactory;

public override DbContextOptionsBuilder AddOptions(DbContextOptionsBuilder builder)
=> TestEnvironment.SetCompatibilityLevelFromEnvironment(base.AddOptions(builder));
Copy link
Copy Markdown
Member

@AndriySvyryd AndriySvyryd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pending Azure SQL special-casing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bump default SQL Server compatibility level from 150 to 160

3 participants