From ac9ebd477e75b40f2422d5cc154c434fdab7060b Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Wed, 6 May 2026 15:17:38 +0200 Subject: [PATCH 1/2] Simplify feature checks to use only compatibility level Remove SQL Server version and Azure checks from feature detection in TestEnvironment. Feature support is now determined solely by compatibility level, streamlining logic and reducing complexity. Update SetCompatibilityLevelFromEnvironment to use GetCompatibilityLevel() directly. Also, notice that Vector is supported on LocalDB provided the latest CU is installed: see https://erikej.github.io/sqlserver/localdb/2026/03/13/localdb-sqlserver-2025.html --- .../TestUtilities/TestEnvironment.cs | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs index d0d5fa5df76..ac0322579d6 100644 --- a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs +++ b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs @@ -259,7 +259,7 @@ public static bool IsTemporalTablesCascadeDeleteSupported try { - _supportsTemporalTablesCascadeDelete = (GetProductMajorVersion() >= 14 || IsAzureSql) && GetCompatibilityLevel() >= 140; + _supportsTemporalTablesCascadeDelete = GetCompatibilityLevel() >= 140; } catch (PlatformNotSupportedException) { @@ -286,7 +286,7 @@ public static bool IsUtf8Supported try { - _supportsUtf8 = (GetProductMajorVersion() >= 15 || IsAzureSql) && GetCompatibilityLevel() >= 150; + _supportsUtf8 = GetCompatibilityLevel() >= 150; } catch (PlatformNotSupportedException) { @@ -313,7 +313,7 @@ public static bool SupportsJsonPathExpressions try { - _supportsJsonPathExpressions = (GetProductMajorVersion() >= 14 || IsAzureSql) && GetCompatibilityLevel() >= 140; + _supportsJsonPathExpressions = GetCompatibilityLevel() >= 140; } catch (PlatformNotSupportedException) { @@ -340,7 +340,7 @@ public static bool IsFunctions2017Supported try { - _supportsFunctions2017 = (GetProductMajorVersion() >= 14 || IsAzureSql) && GetCompatibilityLevel() >= 140; + _supportsFunctions2017 = GetCompatibilityLevel() >= 140; } catch (PlatformNotSupportedException) { @@ -367,7 +367,7 @@ public static bool IsFunctions2019Supported try { - _supportsFunctions2019 = (GetProductMajorVersion() >= 15 || IsAzureSql) && GetCompatibilityLevel() >= 150; + _supportsFunctions2019 = GetCompatibilityLevel() >= 150; } catch (PlatformNotSupportedException) { @@ -394,7 +394,7 @@ public static bool IsFunctions2022Supported try { - _supportsFunctions2022 = (GetProductMajorVersion() >= 16 || IsAzureSql) && GetCompatibilityLevel() >= 160; + _supportsFunctions2022 = GetCompatibilityLevel() >= 160; } catch (PlatformNotSupportedException) { @@ -421,7 +421,7 @@ public static bool IsJsonTypeSupported try { - _isJsonTypeSupported = (GetProductMajorVersion() >= 17 || IsAzureSql) && GetCompatibilityLevel() >= 170; + _isJsonTypeSupported = GetCompatibilityLevel() >= 170; } catch (PlatformNotSupportedException) { @@ -464,7 +464,11 @@ public static byte SqlServerMajorVersion => GetProductMajorVersion(); public static DbContextOptionsBuilder SetCompatibilityLevelFromEnvironment(DbContextOptionsBuilder builder) - => builder.UseSqlServerCompatibilityLevel(SqlServerMajorVersion * 10); + { + builder.UseSqlServerCompatibilityLevel(GetCompatibilityLevel()); + + return builder; + } public static string? ElasticPoolName { get; } = Config["ElasticPoolName"]; From 2c7a074d9a39c5dbdb0a19c929be41165a7fea88 Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Wed, 6 May 2026 15:36:26 +0200 Subject: [PATCH 2/2] Address Copilot comments --- .../TestUtilities/TestEnvironment.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs index ac0322579d6..7ca8e7d5988 100644 --- a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs +++ b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs @@ -139,7 +139,7 @@ public static bool IsHiddenColumnsSupported try { - _supportsHiddenColumns = ((GetProductMajorVersion() >= 13 && GetEngineEdition() != 6) || IsAzureSql) && GetCompatibilityLevel() >= 130; + _supportsHiddenColumns = GetEngineEdition() != 6 && GetCompatibilityLevel() >= 130; } catch (PlatformNotSupportedException) { @@ -448,8 +448,7 @@ public static bool IsVectorTypeSupported try { - _isVectorTypeSupported = ((!IsLocalDb && GetProductMajorVersion() >= 17) || IsAzureSql) - && GetCompatibilityLevel() >= 170; + _isVectorTypeSupported = !IsLocalDb && GetCompatibilityLevel() >= 170; } catch (PlatformNotSupportedException) { @@ -523,7 +522,7 @@ private static int GetCompatibilityLevel() sqlConnection.Open(); using var command = new SqlCommand( - "SELECT compatibility_level FROM sys.databases WHERE [name] = 'master';", sqlConnection); + "SELECT compatibility_level FROM sys.databases WHERE [name] = 'model';", sqlConnection); _compatibilityLevel = (byte)command.ExecuteScalar(); return _compatibilityLevel.Value;