Skip to content

Commit ecfc1ce

Browse files
authored
API review updates (#31673)
1 parent 6a67326 commit ecfc1ce

File tree

68 files changed

+583
-706
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+583
-706
lines changed

src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, out Ex
840840
var propertyGetter = property.GetGetter();
841841
foreach (var value in values)
842842
{
843-
propertyValueList.Add(propertyGetter.GetStructuralTypeClrValue(value));
843+
propertyValueList.Add(propertyGetter.GetClrValue(value));
844844
}
845845

846846
rewrittenSource = Expression.Constant(propertyValueList);
@@ -971,7 +971,7 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p
971971
{
972972
case SqlConstantExpression sqlConstantExpression:
973973
return Expression.Constant(
974-
property.GetGetter().GetStructuralTypeClrValue(sqlConstantExpression.Value!), property.ClrType.MakeNullable());
974+
property.GetGetter().GetClrValue(sqlConstantExpression.Value!), property.ClrType.MakeNullable());
975975

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

10081008
private static List<TProperty> ParameterListValueExtractor<TEntity, TProperty>(
@@ -1016,7 +1016,7 @@ private static List<TProperty> ParameterListValueExtractor<TEntity, TProperty>(
10161016
}
10171017

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

10221022
private static bool IsNullSqlConstantExpression(Expression expression)

src/EFCore.Cosmos/Storage/Internal/CosmosTypeMapping.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected CosmosTypeMapping(CoreTypeMappingParameters parameters)
6060
/// any release. You should only use it directly in your code with extreme caution and knowing that
6161
/// doing so can result in application failures when updating to a new Entity Framework Core release.
6262
/// </summary>
63-
public override CoreTypeMapping Clone(
63+
public override CoreTypeMapping WithComposedConverter(
6464
ValueConverter? converter,
6565
ValueComparer? comparer = null,
6666
ValueComparer? keyComparer = null,

src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ private bool TryRewriteContainsEntity(Expression? source, Expression item, [NotN
12881288
var propertyGetter = property.GetGetter();
12891289
foreach (var value in values)
12901290
{
1291-
propertyValueList.Add(propertyGetter.GetStructuralTypeClrValue(value));
1291+
propertyValueList.Add(propertyGetter.GetClrValue(value));
12921292
}
12931293

12941294
rewrittenSource = Expression.Constant(propertyValueList);
@@ -1436,7 +1436,7 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p
14361436
return Expression.Constant(
14371437
constantExpression.Value is null
14381438
? null
1439-
: property.GetGetter().GetStructuralTypeClrValue(constantExpression.Value),
1439+
: property.GetGetter().GetClrValue(constantExpression.Value),
14401440
property.ClrType.MakeNullable());
14411441

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

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

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

14991499
private static ConstantExpression GetValue(Expression expression)

src/EFCore.InMemory/Storage/Internal/InMemoryTypeMapping.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private InMemoryTypeMapping(CoreTypeMappingParameters parameters)
5353
/// any release. You should only use it directly in your code with extreme caution and knowing that
5454
/// doing so can result in application failures when updating to a new Entity Framework Core release.
5555
/// </summary>
56-
public override CoreTypeMapping Clone(
56+
public override CoreTypeMapping WithComposedConverter(
5757
ValueConverter? converter,
5858
ValueComparer? comparer = null,
5959
ValueComparer? keyComparer = null,

src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ private void HandleChanged(IInvocation invocation, IPropertyBase property, IEqua
9494

9595
if (_checkEquality)
9696
{
97-
var oldValue = property.GetGetter().GetClrValue(invocation.Proxy);
97+
var oldValue = property.GetGetter().GetClrValueUsingContainingEntity(invocation.Proxy);
9898

9999
invocation.Proceed();
100100

src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void HandleChanging(IInvocation invocation, IPropertyBase property, IEqu
9292
{
9393
if (_checkEquality)
9494
{
95-
var oldValue = property.GetGetter().GetClrValue(invocation.Proxy);
95+
var oldValue = property.GetGetter().GetClrValueUsingContainingEntity(invocation.Proxy);
9696
var newValue = invocation.Arguments[^1];
9797

9898
if (!(comparer?.Equals(oldValue, newValue) ?? Equals(oldValue, newValue)))

src/EFCore.Relational/Query/RelationalSqlTranslatingExpressionVisitor.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ private bool TryRewriteContainsEntity(Expression source, Expression item, [NotNu
16841684
var propertyGetter = property.GetGetter();
16851685
foreach (var value in values)
16861686
{
1687-
propertyValueList.Add(propertyGetter.GetStructuralTypeClrValue(value));
1687+
propertyValueList.Add(propertyGetter.GetClrValue(value));
16881688
}
16891689

16901690
rewrittenSource = Expression.Constant(propertyValueList);
@@ -1974,14 +1974,14 @@ private Expression CreatePropertyAccessExpression(Expression target, IProperty p
19741974
return Expression.Constant(
19751975
sqlConstantExpression.Value is null
19761976
? null
1977-
: property.GetGetter().GetStructuralTypeClrValue(sqlConstantExpression.Value),
1977+
: property.GetGetter().GetClrValue(sqlConstantExpression.Value),
19781978
property.ClrType.MakeNullable());
19791979

19801980
case ConstantExpression sqlConstantExpression:
19811981
return Expression.Constant(
19821982
sqlConstantExpression.Value is null
19831983
? null
1984-
: property.GetGetter().GetStructuralTypeClrValue(sqlConstantExpression.Value),
1984+
: property.GetGetter().GetClrValue(sqlConstantExpression.Value),
19851985
property.ClrType.MakeNullable());
19861986

19871987
case SqlParameterExpression sqlParameterExpression
@@ -2035,7 +2035,7 @@ private Expression CreateComplexPropertyAccessExpression(Expression target, ICom
20352035
=> target switch
20362036
{
20372037
SqlConstantExpression constant => Expression.Constant(
2038-
constant.Value is null ? null : complexProperty.GetGetter().GetStructuralTypeClrValue(constant.Value),
2038+
constant.Value is null ? null : complexProperty.GetGetter().GetClrValue(constant.Value),
20392039
complexProperty.ClrType.MakeNullable()),
20402040

20412041
SqlParameterExpression sqlParameterExpression
@@ -2070,11 +2070,11 @@ when memberInitExpression.Bindings.SingleOrDefault(mb => mb.Member.Name == compl
20702070
break;
20712071
}
20722072

2073-
baseValue = complexProperty.GetGetter().GetStructuralTypeClrValue(baseValue);
2073+
baseValue = complexProperty.GetGetter().GetClrValue(baseValue);
20742074
}
20752075
}
20762076

2077-
return baseValue == null ? (T?)(object?)null : (T?)property.GetGetter().GetStructuralTypeClrValue(baseValue);
2077+
return baseValue == null ? (T?)(object?)null : (T?)property.GetGetter().GetClrValue(baseValue);
20782078
}
20792079

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

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

20942094
private sealed class ParameterBasedComplexPropertyChainExpression : Expression

src/EFCore.Relational/Storage/Internal/NullTypeMapping.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
using Microsoft.EntityFrameworkCore.Storage.Json;
55

6-
namespace Microsoft.EntityFrameworkCore.Storage;
6+
namespace Microsoft.EntityFrameworkCore.Storage.Internal;
77

88
/// <summary>
99
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to

src/EFCore.Relational/Storage/RelationalTypeMapping.cs

+6-31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Concurrent;
55
using System.Data;
66
using System.Globalization;
7+
using Microsoft.EntityFrameworkCore.Storage.Internal;
78
using Microsoft.EntityFrameworkCore.Storage.Json;
89

910
namespace Microsoft.EntityFrameworkCore.Storage;
@@ -278,7 +279,7 @@ private static MethodInfo GetDataReaderMethod(string name)
278279
/// <summary>
279280
/// Gets the mapping to be used when the only piece of information is that there is a null value.
280281
/// </summary>
281-
public static readonly NullTypeMapping NullMapping = NullTypeMapping.Default;
282+
public static readonly RelationalTypeMapping NullMapping = NullTypeMapping.Default;
282283

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

423424
/// <summary>
@@ -426,11 +427,11 @@ public virtual RelationalTypeMapping Clone(string storeType, int? size)
426427
/// <param name="precision">The precision of data the property is configured to store, or null if no size is configured.</param>
427428
/// <param name="scale">The scale of data the property is configured to store, or null if no size is configured.</param>
428429
/// <returns>The newly created mapping.</returns>
429-
public virtual RelationalTypeMapping Clone(int? precision, int? scale)
430+
public virtual RelationalTypeMapping WithPrecisionAndScale(int? precision, int? scale)
430431
=> Clone(Parameters.WithPrecisionAndScale(precision, scale));
431432

432433
/// <inheritdoc />
433-
public override CoreTypeMapping Clone(
434+
public override CoreTypeMapping WithComposedConverter(
434435
ValueConverter? converter,
435436
ValueComparer? comparer = null,
436437
ValueComparer? keyComparer = null,
@@ -443,36 +444,10 @@ public override CoreTypeMapping Clone(
443444
/// </summary>
444445
/// <param name="mappingInfo">The mapping info containing the facets to use.</param>
445446
/// <returns>The cloned mapping, or the original mapping if no clone was needed.</returns>
446-
public virtual RelationalTypeMapping Clone(
447+
public virtual RelationalTypeMapping WithTypeMappingInfo(
447448
in RelationalTypeMappingInfo mappingInfo)
448449
=> Clone(Parameters.WithTypeMappingInfo(mappingInfo));
449450

450-
/// <inheritdoc />
451-
public override CoreTypeMapping Clone(
452-
in TypeMappingInfo? mappingInfo = null,
453-
Type? clrType = null,
454-
ValueConverter? converter = null,
455-
ValueComparer? comparer = null,
456-
ValueComparer? keyComparer = null,
457-
ValueComparer? providerValueComparer = null,
458-
CoreTypeMapping? elementMapping = null,
459-
JsonValueReaderWriter? jsonValueReaderWriter = null)
460-
=> Clone(
461-
mappingInfo == null
462-
? null
463-
: new RelationalTypeMappingInfo(
464-
unicode: mappingInfo.Value.IsUnicode,
465-
size: mappingInfo.Value.Size,
466-
precision: mappingInfo.Value.Precision,
467-
scale: mappingInfo.Value.Scale),
468-
clrType,
469-
converter,
470-
comparer,
471-
keyComparer,
472-
providerValueComparer,
473-
elementMapping,
474-
jsonValueReaderWriter);
475-
476451
/// <summary>
477452
/// Clones the type mapping to update any parameter if needed.
478453
/// </summary>

src/EFCore.Relational/Storage/RelationalTypeMappingSource.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
174174

175175
if (mapping != null)
176176
{
177-
mapping = (RelationalTypeMapping)mapping.Clone(
177+
mapping = (RelationalTypeMapping)mapping.WithComposedConverter(
178178
secondConverterInfo.Create(),
179179
jsonValueReaderWriter: mappingInfoUsed.JsonValueReaderWriter);
180180
break;
@@ -184,7 +184,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
184184

185185
if (mapping != null)
186186
{
187-
mapping = (RelationalTypeMapping)mapping.Clone(
187+
mapping = (RelationalTypeMapping)mapping.WithComposedConverter(
188188
converterInfo.Create(),
189189
jsonValueReaderWriter: mappingInfo.JsonValueReaderWriter);
190190
break;
@@ -203,7 +203,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
203203
if (mapping != null
204204
&& customConverter != null)
205205
{
206-
mapping = (RelationalTypeMapping)mapping.Clone(
206+
mapping = (RelationalTypeMapping)mapping.WithComposedConverter(
207207
customConverter,
208208
jsonValueReaderWriter: mappingInfo.JsonValueReaderWriter);
209209
}
@@ -241,7 +241,7 @@ protected override CoreTypeMapping FindMapping(in TypeMappingInfo mappingInfo)
241241
info.WithConverter(
242242
// Note that the converter info is only used temporarily here and never creates an instance.
243243
new ValueConverterInfo(modelType, typeof(string), _ => null!)))!
244-
.Clone(
244+
.WithComposedConverter(
245245
(ValueConverter)Activator.CreateInstance(
246246
typeof(CollectionToJsonStringConverter<>).MakeGenericType(elementType), collectionReaderWriter!)!,
247247
comparer,

src/EFCore.Relational/Storage/ValueConversion/RelationalConverterMappingHints.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public override ConverterMappingHints With(ConverterMappingHints? hints)
7777
(hints as RelationalConverterMappingHints)?.DbType ?? DbType);
7878

7979
/// <inheritdoc />
80-
public override ConverterMappingHints Override(ConverterMappingHints? hints)
80+
public override ConverterMappingHints OverrideWith(ConverterMappingHints? hints)
8181
=> hints == null
8282
? this
8383
: new RelationalConverterMappingHints(

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public SqlServerTypeMappingSource(
233233
/// </summary>
234234
protected override RelationalTypeMapping? FindMapping(in RelationalTypeMappingInfo mappingInfo)
235235
=> base.FindMapping(mappingInfo)
236-
?? FindRawMapping(mappingInfo)?.Clone(mappingInfo);
236+
?? FindRawMapping(mappingInfo)?.WithTypeMappingInfo(mappingInfo);
237237

238238
private RelationalTypeMapping? FindRawMapping(RelationalTypeMappingInfo mappingInfo)
239239
{

src/EFCore.Sqlite.Core/Extensions/SqliteComplexTypePrimitiveCollectionBuilderExtensions.cs

-49
This file was deleted.

0 commit comments

Comments
 (0)