Skip to content

Commit

Permalink
More updates,
Browse files Browse the repository at this point in the history
  • Loading branch information
ajcvickers committed Aug 14, 2024
1 parent 55cc30c commit ca50eb6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,7 @@ public static void SetContainerColumnType(this IMutableEntityType entityType, st
/// <param name="entityType">The entity type.</param>
/// <returns>The database column type.</returns>
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;

/// <summary>
/// Sets the type mapping for the container column to which the entity type is mapped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public SqlServerModificationCommand(in NonTrackedModificationCommandParameters m
/// </summary>
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ public static bool IsFunctions2022Supported
}
}

// TODO:SQLJSON Issue #34414
public static bool IsJsonTypeSupported
=> false;

Expand Down

0 comments on commit ca50eb6

Please sign in to comment.