Skip to content

Commit 8942753

Browse files
committed
Updates based on review feedback
1 parent 5b41676 commit 8942753

23 files changed

+8531
-3074
lines changed

Diff for: src/EFCore/ChangeTracking/NullableValueTypeListComparer.cs renamed to src/EFCore/ChangeTracking/ListOfNullableValueTypesComparer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
1111
/// </summary>
1212
/// <remarks>
1313
/// <para>
14-
/// This comparer should be used for nullable value types. Use <see cref="NullableValueTypeListComparer{TConcreteCollection,TElement}" /> for reference
14+
/// This comparer should be used for nullable value types. Use <see cref="ListOfNullableValueTypesComparer{TConcreteCollection,TElement}" /> for reference
1515
/// types and non-nullable value types.
1616
/// </para>
1717
/// <para>
@@ -20,7 +20,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
2020
/// </remarks>
2121
/// <typeparam name="TConcreteCollection">The collection type to create an index of, if needed.</typeparam>
2222
/// <typeparam name="TElement">The element type.</typeparam>
23-
public sealed class NullableValueTypeListComparer<TConcreteCollection, TElement> : ValueComparer<IEnumerable<TElement?>>
23+
public sealed class ListOfNullableValueTypesComparer<TConcreteCollection, TElement> : ValueComparer<IEnumerable<TElement?>>
2424
where TElement : struct
2525
{
2626
private static readonly bool IsArray = typeof(TConcreteCollection).IsArray;
@@ -33,7 +33,7 @@ public sealed class NullableValueTypeListComparer<TConcreteCollection, TElement>
3333
/// Creates a new instance of the list comparer.
3434
/// </summary>
3535
/// <param name="elementComparer">The comparer to use for comparing elements.</param>
36-
public NullableValueTypeListComparer(ValueComparer elementComparer)
36+
public ListOfNullableValueTypesComparer(ValueComparer elementComparer)
3737
: base(
3838
(a, b) => Compare(a, b, (ValueComparer<TElement?>)elementComparer),
3939
o => GetHashCode(o, (ValueComparer<TElement?>)elementComparer),

Diff for: src/EFCore/ChangeTracking/ObjectListComparer.cs renamed to src/EFCore/ChangeTracking/ListOfReferenceTypesComparer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
2020
/// </remarks>
2121
/// <typeparam name="TConcreteCollection">The collection type to create an index of, if needed.</typeparam>
2222
/// <typeparam name="TElement">The element type.</typeparam>
23-
public sealed class ObjectListComparer<TConcreteCollection, TElement> : ValueComparer<object>
23+
public sealed class ListOfReferenceTypesComparer<TConcreteCollection, TElement> : ValueComparer<object>
2424
where TElement : class
2525
{
2626
private static readonly bool IsArray = typeof(TConcreteCollection).IsArray;
@@ -33,7 +33,7 @@ public sealed class ObjectListComparer<TConcreteCollection, TElement> : ValueCom
3333
/// Creates a new instance of the list comparer.
3434
/// </summary>
3535
/// <param name="elementComparer">The comparer to use for comparing elements.</param>
36-
public ObjectListComparer(ValueComparer elementComparer)
36+
public ListOfReferenceTypesComparer(ValueComparer elementComparer)
3737
: base(
3838
(a, b) => Compare(a, b, elementComparer),
3939
o => GetHashCode((IEnumerable)o, elementComparer),

Diff for: src/EFCore/ChangeTracking/ListComparer.cs renamed to src/EFCore/ChangeTracking/ListOfValueTypesComparer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ namespace Microsoft.EntityFrameworkCore.ChangeTracking;
1212
/// <remarks>
1313
/// <para>
1414
/// This comparer should be used for reference types and non-nullable value types. Use
15-
/// <see cref="NullableValueTypeListComparer{TConcreteCollection, TElement}" /> for nullable value types.
15+
/// <see cref="ListOfNullableValueTypesComparer{TConcreteCollection,TElement}" /> for nullable value types.
1616
/// </para>
1717
/// <para>
1818
/// See <see href="https://aka.ms/efcore-docs-value-comparers">EF Core value comparers</see> for more information and examples.
1919
/// </para>
2020
/// </remarks>
2121
/// <typeparam name="TConcreteCollection">The collection type to create an index of, if needed.</typeparam>
2222
/// <typeparam name="TElement">The element type.</typeparam>
23-
public sealed class ListComparer<TConcreteCollection, TElement> : ValueComparer<IEnumerable<TElement>>
23+
public sealed class ListOfValueTypesComparer<TConcreteCollection, TElement> : ValueComparer<IEnumerable<TElement>>
2424
where TElement : struct
2525
{
2626
private static readonly bool IsArray = typeof(TConcreteCollection).IsArray;
@@ -33,7 +33,7 @@ public sealed class ListComparer<TConcreteCollection, TElement> : ValueComparer<
3333
/// Creates a new instance of the list comparer.
3434
/// </summary>
3535
/// <param name="elementComparer">The comparer to use for comparing elements.</param>
36-
public ListComparer(ValueComparer elementComparer)
36+
public ListOfValueTypesComparer(ValueComparer elementComparer)
3737
: base(
3838
(a, b) => Compare(a, b, (ValueComparer<TElement>)elementComparer),
3939
o => GetHashCode(o, (ValueComparer<TElement>)elementComparer),

Diff for: src/EFCore/Design/Internal/CSharpRuntimeAnnotationCodeGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public static void Create(
418418
var mainBuilder = parameters.MainBuilder;
419419

420420
var constructor = comparer.GetType().GetDeclaredConstructor([typeof(ValueComparer)]);
421-
var elementComparerProperty = comparer.GetType().GetProperty(nameof(ListComparer<object, int>.ElementComparer));
421+
var elementComparerProperty = comparer.GetType().GetProperty(nameof(ListOfValueTypesComparer<object, int>.ElementComparer));
422422
if (constructor == null
423423
|| elementComparerProperty == null)
424424
{

Diff for: src/EFCore/Storage/Json/JsonCollectionOfReferencesReaderWriter.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Microsoft.EntityFrameworkCore.Storage.Json;
1313
/// <typeparam name="TConcreteCollection">The collection type to create an index of, if needed.</typeparam>
1414
/// <typeparam name="TElement">The element type.</typeparam>
1515
public class JsonCollectionOfReferencesReaderWriter<TConcreteCollection, TElement> :
16-
JsonValueReaderWriter<object?>,
16+
JsonValueReaderWriter<object>,
1717
ICompositeJsonValueReaderWriter
1818
where TElement : class?
1919
{
@@ -70,6 +70,7 @@ public override object FromJsonTyped(ref Utf8JsonReaderManager manager, object?
7070
case JsonTokenType.Number:
7171
case JsonTokenType.True:
7272
case JsonTokenType.False:
73+
case JsonTokenType.StartArray:
7374
collection.Add((TElement)_elementReaderWriter.FromJson(ref manager));
7475
break;
7576
case JsonTokenType.Null:
@@ -78,9 +79,6 @@ public override object FromJsonTyped(ref Utf8JsonReaderManager manager, object?
7879
case JsonTokenType.Comment:
7980
case JsonTokenType.EndArray:
8081
break;
81-
case JsonTokenType.StartArray:
82-
collection.Add((TElement)_elementReaderWriter.FromJson(ref manager));
83-
break;
8482
case JsonTokenType.None: // Explicitly listing all states that we throw for
8583
case JsonTokenType.StartObject:
8684
case JsonTokenType.EndObject:

Diff for: src/EFCore/Storage/TypeMappingSourceBase.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ protected virtual bool TryFindJsonCollectionMapping(
177177

178178
elementComparer = (ValueComparer?)Activator.CreateInstance(
179179
elementType.IsNullableValueType()
180-
? typeof(NullableValueTypeListComparer<,>).MakeGenericType(typeToInstantiate, elementType.UnwrapNullableType())
180+
? typeof(ListOfNullableValueTypesComparer<,>).MakeGenericType(typeToInstantiate, elementType.UnwrapNullableType())
181181
: elementType.IsValueType
182-
? typeof(ListComparer<,>).MakeGenericType(typeToInstantiate, elementType)
183-
: typeof(ObjectListComparer<,>).MakeGenericType(typeToInstantiate, elementType),
182+
? typeof(ListOfValueTypesComparer<,>).MakeGenericType(typeToInstantiate, elementType)
183+
: typeof(ListOfReferenceTypesComparer<,>).MakeGenericType(typeToInstantiate, elementType),
184184
elementMapping.Comparer.ToNullableComparer(elementType)!);
185185

186186
return true;

Diff for: test/EFCore.Cosmos.FunctionalTests/EndToEndCosmosTest.cs

+3
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ await Can_add_update_delete_with_collection(
870870
},
871871
new List<byte?[]> { new byte?[] { 3, null }, null });
872872

873+
// TODO: Dictionary mapping Issue #29825
873874
// await Can_add_update_delete_with_collection<IReadOnlyList<Dictionary<string, string>>>(
874875
// new Dictionary<string, string>[] { new() { { "1", null } } },
875876
// c =>
@@ -895,6 +896,7 @@ await Can_add_update_delete_with_collection(
895896
},
896897
new[] { new decimal?[] { 1, 3 } });
897898

899+
// TODO: Dictionary mapping Issue #29825
898900
// await Can_add_update_delete_with_collection(
899901
// new Dictionary<string, List<int>> { { "1", [1] } },
900902
// c =>
@@ -903,6 +905,7 @@ await Can_add_update_delete_with_collection(
903905
// },
904906
// new Dictionary<string, List<int>> { { "1", [1] }, { "2", [3] } });
905907

908+
// TODO: Dictionary mapping Issue #29825
906909
// await Can_add_update_delete_with_collection<IDictionary<string, long?[]>>(
907910
// new SortedDictionary<string, long?[]> { { "2", [2] }, { "1", [1] } },
908911
// c =>

Diff for: test/EFCore.Specification.Tests/Scaffolding/CompiledModelTestBase.cs

+26
Original file line numberDiff line numberDiff line change
@@ -1035,6 +1035,32 @@ public class ManyTypes
10351035
public EnumU32?[] NullableEnumU32AsStringArray { get; set; } = null!;
10361036
public EnumU64?[] NullableEnumU64AsStringArray { get; set; } = null!;
10371037

1038+
public bool[][] BoolNestedCollection { get; set; } = null!;
1039+
public List<byte[]> UInt8NestedCollection { get; set; } = null!;
1040+
public sbyte[][][] Int8NestedCollection { get; set; } = null!;
1041+
public int[][] Int32NestedCollection { get; set; } = null!;
1042+
public IList<long[]>[] Int64NestedCollection { get; set; } = null!;
1043+
public char[][] CharNestedCollection { get; set; } = null!;
1044+
public ICollection<Guid[][]> GuidNestedCollection { get; set; } = null!;
1045+
public string[][] StringNestedCollection { get; set; } = null!;
1046+
public byte[][][] BytesNestedCollection { get; set; } = null!;
1047+
1048+
public byte?[][] NullableUInt8NestedCollection { get; set; } = null!;
1049+
public int?[][] NullableInt32NestedCollection { get; set; } = null!;
1050+
public List<long?[][]> NullableInt64NestedCollection { get; set; } = null!;
1051+
public Guid?[][] NullableGuidNestedCollection { get; set; } = null!;
1052+
public string?[][] NullableStringNestedCollection { get; set; } = null!;
1053+
public byte[]?[][] NullableBytesNestedCollection { get; set; } = null!;
1054+
public IEnumerable<PhysicalAddress?[][]> NullablePhysicalAddressNestedCollection { get; set; } = null!;
1055+
1056+
public Enum8[][] Enum8NestedCollection { get; set; } = null!;
1057+
public List<Enum32>[][] Enum32NestedCollection { get; set; } = null!;
1058+
public EnumU64[][] EnumU64NestedCollection { get; set; } = null!;
1059+
1060+
public Enum8?[][] NullableEnum8NestedCollection { get; set; } = null!;
1061+
public Enum32?[][][] NullableEnum32NestedCollection { get; set; } = null!;
1062+
public EnumU64?[][] NullableEnumU64NestedCollection { get; set; } = null!;
1063+
10381064
public bool BoolToStringConverterProperty { get; set; }
10391065
public bool BoolToTwoValuesConverterProperty { get; set; }
10401066
public bool BoolToZeroOneConverterProperty { get; set; }

0 commit comments

Comments
 (0)