Bump default SQL Server compat level to 160 (SQL Server 2022)#38199
Conversation
There was a problem hiding this comment.
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
SqlServerDefaultCompatibilityLevelfrom 150 (SQL Server 2019) to 160 (SQL Server 2022). - Update the inline compatibility-level reference comments in
SqlServerOptionsExtension.
There was a problem hiding this comment.
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)); |
| 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)); |
AndriySvyryd
left a comment
There was a problem hiding this comment.
Pending Azure SQL special-casing
This seems wrong... Azure SQL should report ProductVersion just like regular on-prem SQL Server, so we shouldn't normally be seeing 120. Besides, if the ProductVersion is somehow really 120, I think that means the compat level is set very low by the user, and then we indeed shouldn't be generating new SQL functions like GREATEST/LEAST. I'll go ahead and merge, if we run into trouble around this in the future, we can go deeper. |
|
@roji It is actually wrong to derive the compat level from product version in this case for Azure SQL |
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