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 1 commit
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
Prev Previous commit
API review updates (#31673)
  • Loading branch information
ajcvickers authored Sep 10, 2023
commit ecfc1ced12714a972f538a071d23cdf34aafbb2e
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
2 changes: 1 addition & 1 deletion src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ 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,
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ 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,
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 @@ -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
37 changes: 6 additions & 31 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 @@ -278,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 @@ -417,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 @@ -426,11 +427,11 @@ 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,
Expand All @@ -443,36 +444,10 @@ public override CoreTypeMapping Clone(
/// </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
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)

if (mapping != null)
{
mapping = (RelationalTypeMapping)mapping.Clone(
mapping = (RelationalTypeMapping)mapping.WithComposedConverter(
secondConverterInfo.Create(),
jsonValueReaderWriter: mappingInfoUsed.JsonValueReaderWriter);
break;
Expand All @@ -184,7 +184,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)

if (mapping != null)
{
mapping = (RelationalTypeMapping)mapping.Clone(
mapping = (RelationalTypeMapping)mapping.WithComposedConverter(
converterInfo.Create(),
jsonValueReaderWriter: mappingInfo.JsonValueReaderWriter);
break;
Expand All @@ -203,7 +203,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
if (mapping != null
&& customConverter != null)
{
mapping = (RelationalTypeMapping)mapping.Clone(
mapping = (RelationalTypeMapping)mapping.WithComposedConverter(
customConverter,
jsonValueReaderWriter: mappingInfo.JsonValueReaderWriter);
}
Expand Down Expand Up @@ -241,7 +241,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
info.WithConverter(
// Note that the converter info is only used temporarily here and never creates an instance.
new ValueConverterInfo(modelType, typeof(string), _ => null!)))!
.Clone(
.WithComposedConverter(
(ValueConverter)Activator.CreateInstance(
typeof(CollectionToJsonStringConverter<>).MakeGenericType(elementType), collectionReaderWriter!)!,
comparer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override ConverterMappingHints With(ConverterMappingHints? hints)
(hints as RelationalConverterMappingHints)?.DbType ?? DbType);

/// <inheritdoc />
public override ConverterMappingHints Override(ConverterMappingHints? hints)
public override ConverterMappingHints OverrideWith(ConverterMappingHints? hints)
=> hints == null
? this
: new RelationalConverterMappingHints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public SqlServerTypeMappingSource(
/// </summary>
protected override RelationalTypeMapping? FindMapping(in RelationalTypeMappingInfo mappingInfo)
=> base.FindMapping(mappingInfo)
?? FindRawMapping(mappingInfo)?.Clone(mappingInfo);
?? FindRawMapping(mappingInfo)?.WithTypeMappingInfo(mappingInfo);

private RelationalTypeMapping? FindRawMapping(RelationalTypeMappingInfo mappingInfo)
{
Expand Down

This file was deleted.

Loading