From ca50eb60c6c46b18eb03f6fe503ed65c4b1e87e4 Mon Sep 17 00:00:00 2001 From: Arthur Vickers Date: Wed, 14 Aug 2024 12:30:51 +0100 Subject: [PATCH] More updates, --- .../Extensions/RelationalEntityTypeExtensions.cs | 3 +-- .../Query/Internal/SqlServerJsonPostprocessor.cs | 12 ++++++------ .../Update/Internal/SqlServerModificationCommand.cs | 1 + .../TestUtilities/TestEnvironment.cs | 1 + 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs index cb2e437c378..93beae7be86 100644 --- a/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs +++ b/src/EFCore.Relational/Extensions/RelationalEntityTypeExtensions.cs @@ -1645,8 +1645,7 @@ public static void SetContainerColumnType(this IMutableEntityType entityType, st /// The entity type. /// The database column type. public static string? GetContainerColumnType(this IReadOnlyEntityType entityType) - => entityType.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value as string - ?? entityType.FindOwnership()?.PrincipalEntityType.GetContainerColumnType(); + => entityType.FindAnnotation(RelationalAnnotationNames.ContainerColumnType)?.Value as string; /// /// Sets the type mapping for the container column to which the entity type is mapped. diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs index 4c86a239680..aaa815f459b 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerJsonPostprocessor.cs @@ -77,13 +77,11 @@ public Expression Process(Expression expression) var table = selectExpression.Tables[i]; if (table.UnwrapJoin() is SqlServerOpenJsonExpression { ColumnInfos: { } columnInfos } openJsonExpression - // Condition 1: an ordering/projection still refers to the OPENJSON's [key] column - it needs to be preserved. && (selectExpression.Orderings.Select(o => o.Expression) .Concat(selectExpression.Projection.Select(p => p.Expression)) .Any(x => IsKeyColumn(x, openJsonExpression.Alias)) || - // Condition 2: a column type in the WITH clause is a SQL Server "CLR type" (e.g. hierarchy id). // These are not supported by OPENJSON with WITH. columnInfos.Any(c => c.TypeMapping.StoreType is "hierarchyid"))) @@ -252,12 +250,14 @@ when _columnsToRewrite.TryGetValue((columnExpression.TableAlias, columnExpressio } case SqlServerOpenJsonExpression openJsonExpression: - // Currently, OPEN_JSON does not accept a "json" type, so we must cast the value to a string. + // Currently, OPENJSON does not accept a "json" type, so we must cast the value to a string. // We do this for both the case where is a string type mapping for a top-level property with the store type // of "json", and when there is an "element" type mapping to something in the document but is now being used - // with OPEN_JSON. - return openJsonExpression is { JsonExpression.TypeMapping: SqlServerStringTypeMapping { StoreType: "json" } } or - { JsonExpression.TypeMapping: SqlServerOwnedJsonTypeMapping { StoreType: "json" } } + // with OPENJSON. + return openJsonExpression.JsonExpression.TypeMapping + is SqlServerStringTypeMapping { StoreType: "json" } + or SqlServerOwnedJsonTypeMapping { StoreType: "json" } + ? openJsonExpression.Update( new SqlUnaryExpression( ExpressionType.Convert, diff --git a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommand.cs b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommand.cs index ed1fd88ebbe..d4d8ae07587 100644 --- a/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommand.cs +++ b/src/EFCore.SqlServer/Update/Internal/SqlServerModificationCommand.cs @@ -43,6 +43,7 @@ public SqlServerModificationCommand(in NonTrackedModificationCommandParameters m /// protected override void ProcessSinglePropertyJsonUpdate(ref ColumnModificationParameters parameters) { + // See: Issue #34432 var property = parameters.Property!; var mapping = property.GetRelationalTypeMapping(); var propertyProviderClrType = (mapping.Converter?.ProviderClrType ?? property.ClrType).UnwrapNullableType(); diff --git a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs index 586583580f2..34e7e76ab28 100644 --- a/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs +++ b/test/EFCore.SqlServer.FunctionalTests/TestUtilities/TestEnvironment.cs @@ -398,6 +398,7 @@ public static bool IsFunctions2022Supported } } + // TODO:SQLJSON Issue #34414 public static bool IsJsonTypeSupported => false;