Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automated] Merge branch 'release/8.0' => 'main' #31669

Merged
merged 4 commits into from
Sep 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, out Ex
var propertyGetter = property.GetGetter();
foreach (var value in values)
{
propertyValueList.Add(propertyGetter.GetStructuralTypeClrValue(value));
propertyValueList.Add(propertyGetter.GetClrValue(value));
}

rewrittenSource = Expression.Constant(propertyValueList);
Expand Down Expand Up @@ -971,7 +971,7 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p
{
case SqlConstantExpression sqlConstantExpression:
return Expression.Constant(
property.GetGetter().GetStructuralTypeClrValue(sqlConstantExpression.Value!), property.ClrType.MakeNullable());
property.GetGetter().GetClrValue(sqlConstantExpression.Value!), property.ClrType.MakeNullable());

case SqlParameterExpression sqlParameterExpression
when sqlParameterExpression.Name.StartsWith(QueryCompilationContext.QueryParameterPrefix, StringComparison.Ordinal):
Expand Down Expand Up @@ -1002,7 +1002,7 @@ when memberInitExpression.Bindings.SingleOrDefault(
private static T ParameterValueExtractor<T>(QueryContext context, string baseParameterName, IProperty property)
{
var baseParameter = context.ParameterValues[baseParameterName];
return baseParameter == null ? (T)(object)null : (T)property.GetGetter().GetStructuralTypeClrValue(baseParameter);
return baseParameter == null ? (T)(object)null : (T)property.GetGetter().GetClrValue(baseParameter);
}

private static List<TProperty> ParameterListValueExtractor<TEntity, TProperty>(
Expand All @@ -1016,7 +1016,7 @@ private static List<TProperty> ParameterListValueExtractor<TEntity, TProperty>(
}

var getter = property.GetGetter();
return baseListParameter.Select(e => e != null ? (TProperty)getter.GetStructuralTypeClrValue(e) : (TProperty)(object)null).ToList();
return baseListParameter.Select(e => e != null ? (TProperty)getter.GetClrValue(e) : (TProperty)(object)null).ToList();
}

private static bool IsNullSqlConstantExpression(Expression expression)
Expand Down
5 changes: 3 additions & 2 deletions src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ protected CosmosTypeMapping(CoreTypeMappingParameters parameters)
/// 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.
/// </summary>
public override CoreTypeMapping Clone(
public override CoreTypeMapping WithComposedConverter(
ValueConverter? converter,
ValueComparer? comparer = null,
ValueComparer? keyComparer = null,
CoreTypeMapping? elementMapping = null,
JsonValueReaderWriter? jsonValueReaderWriter = null)
=> new CosmosTypeMapping(Parameters.WithComposedConverter(converter, comparer, elementMapping, jsonValueReaderWriter));
=> new CosmosTypeMapping(Parameters.WithComposedConverter(converter, comparer, keyComparer, elementMapping, jsonValueReaderWriter));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ protected virtual void GenerateComplexProperty(
{
stringBuilder
.AppendLine()
.Append(".IsRequired()");
.Append(complexTypeBuilderName)
.AppendLine(".IsRequired();");
}

GenerateProperties(complexTypeBuilderName, complexType.GetDeclaredProperties(), stringBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ private bool TryRewriteContainsEntity(Expression? source, Expression item, [NotN
var propertyGetter = property.GetGetter();
foreach (var value in values)
{
propertyValueList.Add(propertyGetter.GetStructuralTypeClrValue(value));
propertyValueList.Add(propertyGetter.GetClrValue(value));
}

rewrittenSource = Expression.Constant(propertyValueList);
Expand Down Expand Up @@ -1436,7 +1436,7 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p
return Expression.Constant(
constantExpression.Value is null
? null
: property.GetGetter().GetStructuralTypeClrValue(constantExpression.Value),
: property.GetGetter().GetClrValue(constantExpression.Value),
property.ClrType.MakeNullable());

case MethodCallExpression { Method.IsGenericMethod: true } methodCallExpression
Expand Down Expand Up @@ -1479,7 +1479,7 @@ when CanEvaluate(memberInitExpression):
private static T? ParameterValueExtractor<T>(QueryContext context, string baseParameterName, IProperty property)
{
var baseParameter = context.ParameterValues[baseParameterName];
return baseParameter == null ? (T?)(object?)null : (T?)property.GetGetter().GetStructuralTypeClrValue(baseParameter);
return baseParameter == null ? (T?)(object?)null : (T?)property.GetGetter().GetClrValue(baseParameter);
}

private static List<TProperty?>? ParameterListValueExtractor<TEntity, TProperty>(
Expand All @@ -1493,7 +1493,7 @@ when CanEvaluate(memberInitExpression):
}

var getter = property.GetGetter();
return baseListParameter.Select(e => e != null ? (TProperty?)getter.GetStructuralTypeClrValue(e) : (TProperty?)(object?)null).ToList();
return baseListParameter.Select(e => e != null ? (TProperty?)getter.GetClrValue(e) : (TProperty?)(object?)null).ToList();
}

private static ConstantExpression GetValue(Expression expression)
Expand Down
5 changes: 3 additions & 2 deletions src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ private InMemoryTypeMapping(CoreTypeMappingParameters parameters)
/// 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.
/// </summary>
public override CoreTypeMapping Clone(
public override CoreTypeMapping WithComposedConverter(
ValueConverter? converter,
ValueComparer? comparer = null,
ValueComparer? keyComparer = null,
CoreTypeMapping? elementMapping = null,
JsonValueReaderWriter? jsonValueReaderWriter = null)
=> new InMemoryTypeMapping(Parameters.WithComposedConverter(converter, comparer, elementMapping, jsonValueReaderWriter));
=> new InMemoryTypeMapping(Parameters.WithComposedConverter(converter, comparer, keyComparer, elementMapping, jsonValueReaderWriter));

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private void HandleChanged(IInvocation invocation, IPropertyBase property, IEqua

if (_checkEquality)
{
var oldValue = property.GetGetter().GetClrValue(invocation.Proxy);
var oldValue = property.GetGetter().GetClrValueUsingContainingEntity(invocation.Proxy);

invocation.Proceed();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void HandleChanging(IInvocation invocation, IPropertyBase property, IEqu
{
if (_checkEquality)
{
var oldValue = property.GetGetter().GetClrValue(invocation.Proxy);
var oldValue = property.GetGetter().GetClrValueUsingContainingEntity(invocation.Proxy);
var newValue = invocation.Arguments[^1];

if (!(comparer?.Equals(oldValue, newValue) ?? Equals(oldValue, newValue)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, [NotNu
var propertyGetter = property.GetGetter();
foreach (var value in values)
{
propertyValueList.Add(propertyGetter.GetStructuralTypeClrValue(value));
propertyValueList.Add(propertyGetter.GetClrValue(value));
}

rewrittenSource = Expression.Constant(propertyValueList);
Expand Down Expand Up @@ -1974,14 +1974,14 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p
return Expression.Constant(
sqlConstantExpression.Value is null
? null
: property.GetGetter().GetStructuralTypeClrValue(sqlConstantExpression.Value),
: property.GetGetter().GetClrValue(sqlConstantExpression.Value),
property.ClrType.MakeNullable());

case ConstantExpression sqlConstantExpression:
return Expression.Constant(
sqlConstantExpression.Value is null
? null
: property.GetGetter().GetStructuralTypeClrValue(sqlConstantExpression.Value),
: property.GetGetter().GetClrValue(sqlConstantExpression.Value),
property.ClrType.MakeNullable());

case SqlParameterExpression sqlParameterExpression
Expand Down Expand Up @@ -2035,7 +2035,7 @@ private Expression CreateComplexPropertyAccessExpression(Expression target, ICom
=> target switch
{
SqlConstantExpression constant => Expression.Constant(
constant.Value is null ? null : complexProperty.GetGetter().GetStructuralTypeClrValue(constant.Value),
constant.Value is null ? null : complexProperty.GetGetter().GetClrValue(constant.Value),
complexProperty.ClrType.MakeNullable()),

SqlParameterExpression sqlParameterExpression
Expand Down Expand Up @@ -2070,11 +2070,11 @@ when memberInitExpression.Bindings.SingleOrDefault(mb => mb.Member.Name == compl
break;
}

baseValue = complexProperty.GetGetter().GetStructuralTypeClrValue(baseValue);
baseValue = complexProperty.GetGetter().GetClrValue(baseValue);
}
}

return baseValue == null ? (T?)(object?)null : (T?)property.GetGetter().GetStructuralTypeClrValue(baseValue);
return baseValue == null ? (T?)(object?)null : (T?)property.GetGetter().GetClrValue(baseValue);
}

private static List<TProperty?>? ParameterListValueExtractor<TEntity, TProperty>(
Expand All @@ -2088,7 +2088,7 @@ when memberInitExpression.Bindings.SingleOrDefault(mb => mb.Member.Name == compl
}

var getter = property.GetGetter();
return baseListParameter.Select(e => e != null ? (TProperty?)getter.GetStructuralTypeClrValue(e) : (TProperty?)(object?)null).ToList();
return baseListParameter.Select(e => e != null ? (TProperty?)getter.GetClrValue(e) : (TProperty?)(object?)null).ToList();
}

private sealed class ParameterBasedComplexPropertyChainExpression : Expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -808,8 +808,7 @@ when entityType.IsMappedToJson():
// (OPENJSON, json_each, etc), but we can't use it for distinct, as it would warp the results.
// Instead, we will treat every non-key property as identifier.

// TODO: hack/workaround, see #31398
foreach (var property in entityType.GetDeclaredProperties().Where(p => !p.IsPrimaryKey() && p.GetRelationalTypeMapping().ElementTypeMapping == null))
foreach (var property in entityType.GetDeclaredProperties().Where(p => !p.IsPrimaryKey()))
{
typeProjectionIdentifiers.Add(entityProjection.BindProperty(property));
typeProjectionValueComparers.Add(property.GetKeyValueComparer());
Expand All @@ -826,8 +825,7 @@ when entityType.IsMappedToJson():
// entity type would have wiped the identifiers when generating the join.
Check.DebugAssert(primaryKey != null, "primary key is null.");

// TODO: hack/workaround, see #31398
foreach (var property in primaryKey.Properties.Where(x => x.GetRelationalTypeMapping().ElementTypeMapping == null))
foreach (var property in primaryKey.Properties)
{
typeProjectionIdentifiers.Add(entityProjection.BindProperty(property));
typeProjectionValueComparers.Add(property.GetKeyValueComparer());
Expand Down Expand Up @@ -1851,7 +1849,7 @@ ConstantExpression AddStructuralTypeProjection(StructuralTypeProjectionExpressio
{
ownerEntity = ownership.PrincipalEntityType;
}
}
}
while (ownerEntity.IsMappedToJson());

var keyPropertyCount = ownerEntity.FindPrimaryKey()!.Properties.Count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

using Microsoft.EntityFrameworkCore.Storage.Json;

namespace Microsoft.EntityFrameworkCore.Storage;
namespace Microsoft.EntityFrameworkCore.Storage.Internal;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
44 changes: 11 additions & 33 deletions src/EFCore.Relational/Storage/RelationalTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Concurrent;
using System.Data;
using System.Globalization;
using Microsoft.EntityFrameworkCore.Storage.Internal;
using Microsoft.EntityFrameworkCore.Storage.Json;

namespace Microsoft.EntityFrameworkCore.Storage;
Expand Down Expand Up @@ -231,16 +232,18 @@ public RelationalTypeMappingParameters WithScale(int? scale)
/// </summary>
/// <param name="converter">The converter.</param>
/// <param name="comparer">The comparer.</param>
/// <param name="keyComparer">The key comparer.</param>
/// <param name="elementMapping">The element mapping, or <see langword="null" /> for non-collection mappings.</param>
/// <param name="jsonValueReaderWriter">The JSON reader/writer, or <see langword="null" /> to leave unchanged.</param>
/// <returns>The new parameter object.</returns>
public RelationalTypeMappingParameters WithComposedConverter(
ValueConverter? converter,
ValueComparer? comparer,
ValueComparer? keyComparer,
CoreTypeMapping? elementMapping,
JsonValueReaderWriter? jsonValueReaderWriter)
=> new(
CoreParameters.WithComposedConverter(converter, comparer, elementMapping, jsonValueReaderWriter),
CoreParameters.WithComposedConverter(converter, comparer, keyComparer, elementMapping, jsonValueReaderWriter),
StoreType,
StoreTypePostfix,
DbType,
Expand Down Expand Up @@ -276,7 +279,7 @@ private static MethodInfo GetDataReaderMethod(string name)
/// <summary>
/// Gets the mapping to be used when the only piece of information is that there is a null value.
/// </summary>
public static readonly NullTypeMapping NullMapping = NullTypeMapping.Default;
public static readonly RelationalTypeMapping NullMapping = NullTypeMapping.Default;

/// <summary>
/// Initializes a new instance of the <see cref="RelationalTypeMapping" /> class.
Expand Down Expand Up @@ -415,7 +418,7 @@ protected override CoreTypeMapping Clone(CoreTypeMappingParameters parameters)
/// <param name="storeType">The name of the database type.</param>
/// <param name="size">The size of data the property is configured to store, or null if no size is configured.</param>
/// <returns>The newly created mapping.</returns>
public virtual RelationalTypeMapping Clone(string storeType, int? size)
public virtual RelationalTypeMapping WithStoreTypeAndSize(string storeType, int? size)
=> Clone(Parameters.WithStoreTypeAndSize(storeType, size));

/// <summary>
Expand All @@ -424,52 +427,27 @@ public virtual RelationalTypeMapping Clone(string storeType, int? size)
/// <param name="precision">The precision of data the property is configured to store, or null if no size is configured.</param>
/// <param name="scale">The scale of data the property is configured to store, or null if no size is configured.</param>
/// <returns>The newly created mapping.</returns>
public virtual RelationalTypeMapping Clone(int? precision, int? scale)
public virtual RelationalTypeMapping WithPrecisionAndScale(int? precision, int? scale)
=> Clone(Parameters.WithPrecisionAndScale(precision, scale));

/// <inheritdoc />
public override CoreTypeMapping Clone(
public override CoreTypeMapping WithComposedConverter(
ValueConverter? converter,
ValueComparer? comparer = null,
ValueComparer? keyComparer = null,
CoreTypeMapping? elementMapping = null,
JsonValueReaderWriter? jsonValueReaderWriter = null)
=> Clone(Parameters.WithComposedConverter(converter, comparer, elementMapping, jsonValueReaderWriter));
=> Clone(Parameters.WithComposedConverter(converter, comparer, keyComparer, elementMapping, jsonValueReaderWriter));

/// <summary>
/// Clones the type mapping to update facets from the mapping info, if needed.
/// </summary>
/// <param name="mappingInfo">The mapping info containing the facets to use.</param>
/// <returns>The cloned mapping, or the original mapping if no clone was needed.</returns>
public virtual RelationalTypeMapping Clone(
public virtual RelationalTypeMapping WithTypeMappingInfo(
in RelationalTypeMappingInfo mappingInfo)
=> Clone(Parameters.WithTypeMappingInfo(mappingInfo));

/// <inheritdoc />
public override CoreTypeMapping Clone(
in TypeMappingInfo? mappingInfo = null,
Type? clrType = null,
ValueConverter? converter = null,
ValueComparer? comparer = null,
ValueComparer? keyComparer = null,
ValueComparer? providerValueComparer = null,
CoreTypeMapping? elementMapping = null,
JsonValueReaderWriter? jsonValueReaderWriter = null)
=> Clone(
mappingInfo == null
? null
: new RelationalTypeMappingInfo(
unicode: mappingInfo.Value.IsUnicode,
size: mappingInfo.Value.Size,
precision: mappingInfo.Value.Precision,
scale: mappingInfo.Value.Scale),
clrType,
converter,
comparer,
keyComparer,
providerValueComparer,
elementMapping,
jsonValueReaderWriter);

/// <summary>
/// Clones the type mapping to update any parameter if needed.
/// </summary>
Expand Down
Loading