Skip to content

Commit 4be400a

Browse files
authored
Switch to using SqlDbType.Json (dotnet#36397)
Closes dotnet#34414
1 parent 48e0367 commit 4be400a

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

src/EFCore.SqlServer/Storage/Internal/SqlServerOwnedJsonTypeMapping.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ protected override void ConfigureParameter(DbParameter parameter)
127127
if (StoreType == "json"
128128
&& parameter is SqlParameter sqlParameter) // To avoid crashing wrapping providers
129129
{
130-
// TODO:SQLJSON Issue #34414
131-
sqlParameter.SqlDbType = ((SqlDbType)35);
130+
sqlParameter.SqlDbType = SqlDbType.Json;
132131
}
133132

134133
base.ConfigureParameter(parameter);

src/EFCore.SqlServer/Storage/Internal/SqlServerStringTypeMapping.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public class SqlServerStringTypeMapping : StringTypeMapping
4040
/// any release. You should only use it directly in your code with extreme caution and knowing that
4141
/// doing so can result in application failures when updating to a new Entity Framework Core release.
4242
/// </summary>
43-
// TODO:SQLJSON Issue #34414
44-
public static SqlServerStringTypeMapping JsonTypeDefault { get; } = new("json", sqlDbType: (SqlDbType)35);
43+
public static SqlServerStringTypeMapping JsonTypeDefault { get; } = new("json", sqlDbType: SqlDbType.Json);
4544

4645
/// <summary>
4746
/// 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)
158157
var value = parameter.Value;
159158
var length = (value as string)?.Length;
160159

161-
// TODO:SQLJSON Issue #34414
162160
var sqlDbType = _sqlDbType
163-
?? (StoreType == "json" ? (SqlDbType)35 : null);
161+
?? (StoreType == "json" ? SqlDbType.Json : null);
164162

165163
if (sqlDbType.HasValue
166164
&& parameter is SqlParameter sqlParameter) // To avoid crashing wrapping providers

test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public static class TestEnvironment
4343

4444
private static bool? _supportsJsonPathExpressions;
4545

46+
private static bool? _isJsonTypeSupported;
47+
4648
private static bool? _isVectorTypeSupported;
4749

4850
private static bool? _supportsFunctions2017;
@@ -400,9 +402,32 @@ public static bool IsFunctions2022Supported
400402
}
401403
}
402404

403-
// TODO:SQLJSON Issue #34414
404405
public static bool IsJsonTypeSupported
405-
=> false;
406+
{
407+
get
408+
{
409+
if (!IsConfigured)
410+
{
411+
return false;
412+
}
413+
414+
if (_isJsonTypeSupported.HasValue)
415+
{
416+
return _isJsonTypeSupported.Value;
417+
}
418+
419+
try
420+
{
421+
_isJsonTypeSupported = GetProductMajorVersion() >= 17 || IsSqlAzure;
422+
}
423+
catch (PlatformNotSupportedException)
424+
{
425+
_isJsonTypeSupported = false;
426+
}
427+
428+
return _isJsonTypeSupported.Value;
429+
}
430+
}
406431

407432
public static bool IsVectorTypeSupported
408433
{

0 commit comments

Comments
 (0)