diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerOwnedJsonTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerOwnedJsonTypeMapping.cs index 801ac044755..658d6240e02 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerOwnedJsonTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerOwnedJsonTypeMapping.cs @@ -127,8 +127,7 @@ protected override void ConfigureParameter(DbParameter parameter) if (StoreType == "json" && parameter is SqlParameter sqlParameter) // To avoid crashing wrapping providers { - // TODO:SQLJSON Issue #34414 - sqlParameter.SqlDbType = ((SqlDbType)35); + sqlParameter.SqlDbType = SqlDbType.Json; } base.ConfigureParameter(parameter); diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs index 89eb2779f4f..d265674f6ca 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs @@ -40,8 +40,7 @@ public class SqlServerStringTypeMapping : StringTypeMapping /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// - // TODO:SQLJSON Issue #34414 - public static SqlServerStringTypeMapping JsonTypeDefault { get; } = new("json", sqlDbType: (SqlDbType)35); + public static SqlServerStringTypeMapping JsonTypeDefault { get; } = new("json", sqlDbType: SqlDbType.Json); /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -158,9 +157,8 @@ protected override void ConfigureParameter(DbParameter parameter) var value = parameter.Value; var length = (value as string)?.Length; - // TODO:SQLJSON Issue #34414 var sqlDbType = _sqlDbType - ?? (StoreType == "json" ? (SqlDbType)35 : null); + ?? (StoreType == "json" ? SqlDbType.Json : null); if (sqlDbType.HasValue && parameter is SqlParameter sqlParameter) // To avoid crashing wrapping providers diff --git a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs index f31640344ab..085186e7dce 100644 --- a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs +++ b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs @@ -43,6 +43,8 @@ public static class TestEnvironment private static bool? _supportsJsonPathExpressions; + private static bool? _isJsonTypeSupported; + private static bool? _isVectorTypeSupported; private static bool? _supportsFunctions2017; @@ -400,9 +402,32 @@ public static bool IsFunctions2022Supported } } - // TODO:SQLJSON Issue #34414 public static bool IsJsonTypeSupported - => false; + { + get + { + if (!IsConfigured) + { + return false; + } + + if (_isJsonTypeSupported.HasValue) + { + return _isJsonTypeSupported.Value; + } + + try + { + _isJsonTypeSupported = GetProductMajorVersion() >= 17 || IsSqlAzure; + } + catch (PlatformNotSupportedException) + { + _isJsonTypeSupported = false; + } + + return _isJsonTypeSupported.Value; + } + } public static bool IsVectorTypeSupported {