diff --git a/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs b/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs index f5d1e64adba..e78c7bf02b8 100644 --- a/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs +++ b/src/EFCore.Proxies/Proxies/Internal/PropertyChangedInterceptor.cs @@ -75,7 +75,7 @@ public virtual void Intercept(IInvocation invocation) if (navigation != null) { - HandleChanged(invocation, navigation, LegacyReferenceEqualityComparer.Instance); + HandleChanged(invocation, navigation, ReferenceEqualityComparer.Instance); } else { diff --git a/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs b/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs index 6bd1c5125eb..8b467c0e563 100644 --- a/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs +++ b/src/EFCore.Proxies/Proxies/Internal/PropertyChangingInterceptor.cs @@ -75,7 +75,7 @@ public virtual void Intercept(IInvocation invocation) if (navigation != null) { - HandleChanging(invocation, navigation, LegacyReferenceEqualityComparer.Instance); + HandleChanging(invocation, navigation, ReferenceEqualityComparer.Instance); } else { diff --git a/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs b/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs index 78a51e11b72..6cf339b80a1 100644 --- a/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs +++ b/src/EFCore.Relational/Query/Internal/FromSqlParameterExpandingExpressionVisitor.cs @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal; public class FromSqlParameterExpandingExpressionVisitor : ExpressionVisitor { private readonly IDictionary _visitedFromSqlExpressions - = new Dictionary(LegacyReferenceEqualityComparer.Instance); + = new Dictionary(ReferenceEqualityComparer.Instance); private readonly ISqlExpressionFactory _sqlExpressionFactory; private readonly IRelationalTypeMappingSource _typeMappingSource; diff --git a/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs b/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs index 34add1c5dac..349db5a3e7d 100644 --- a/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs +++ b/src/EFCore/ChangeTracking/Internal/ChangeDetector.cs @@ -334,7 +334,7 @@ public bool DetectNavigationChange(InternalEntityEntry entry, INavigationBase na var snapshotCollection = (IEnumerable?)snapshotValue; var currentCollection = (IEnumerable?)currentValue; - var removed = new HashSet(LegacyReferenceEqualityComparer.Instance); + var removed = new HashSet(ReferenceEqualityComparer.Instance); if (snapshotCollection != null) { foreach (var entity in snapshotCollection) @@ -343,7 +343,7 @@ public bool DetectNavigationChange(InternalEntityEntry entry, INavigationBase na } } - var added = new HashSet(LegacyReferenceEqualityComparer.Instance); + var added = new HashSet(ReferenceEqualityComparer.Instance); if (currentCollection != null) { foreach (var entity in currentCollection) diff --git a/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs b/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs index 2cc5a760bbc..804b1cd9ec0 100644 --- a/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs +++ b/src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs @@ -73,24 +73,24 @@ public EntityReferenceMap(bool hasSubMap) switch (state) { case EntityState.Detached: - _detachedReferenceMap ??= new Dictionary(LegacyReferenceEqualityComparer.Instance); + _detachedReferenceMap ??= new Dictionary(ReferenceEqualityComparer.Instance); _detachedReferenceMap[mapKey] = entry; break; case EntityState.Unchanged: _unchangedReferenceMap ??= - new Dictionary(LegacyReferenceEqualityComparer.Instance); + new Dictionary(ReferenceEqualityComparer.Instance); _unchangedReferenceMap[mapKey] = entry; break; case EntityState.Deleted: - _deletedReferenceMap ??= new Dictionary(LegacyReferenceEqualityComparer.Instance); + _deletedReferenceMap ??= new Dictionary(ReferenceEqualityComparer.Instance); _deletedReferenceMap[mapKey] = entry; break; case EntityState.Modified: - _modifiedReferenceMap ??= new Dictionary(LegacyReferenceEqualityComparer.Instance); + _modifiedReferenceMap ??= new Dictionary(ReferenceEqualityComparer.Instance); _modifiedReferenceMap[mapKey] = entry; break; case EntityState.Added: - _addedReferenceMap ??= new Dictionary(LegacyReferenceEqualityComparer.Instance); + _addedReferenceMap ??= new Dictionary(ReferenceEqualityComparer.Instance); _addedReferenceMap[mapKey] = entry; break; } diff --git a/src/EFCore/ChangeTracking/Internal/IdentityMap.cs b/src/EFCore/ChangeTracking/Internal/IdentityMap.cs index b150a0ac0b6..1e4af44a629 100644 --- a/src/EFCore/ChangeTracking/Internal/IdentityMap.cs +++ b/src/EFCore/ChangeTracking/Internal/IdentityMap.cs @@ -355,7 +355,7 @@ private void Add(TKey key, InternalEntityEntry entry, bool updateDuplicate) /// public virtual IDependentsMap GetDependentsMap(IForeignKey foreignKey) { - _dependentMaps ??= new Dictionary(LegacyReferenceEqualityComparer.Instance); + _dependentMaps ??= new Dictionary(ReferenceEqualityComparer.Instance); if (!_dependentMaps.TryGetValue(foreignKey, out var map)) { diff --git a/src/EFCore/ChangeTracking/Internal/RelationshipsSnapshot.cs b/src/EFCore/ChangeTracking/Internal/RelationshipsSnapshot.cs index e95c0e4683d..0808c76618d 100644 --- a/src/EFCore/ChangeTracking/Internal/RelationshipsSnapshot.cs +++ b/src/EFCore/ChangeTracking/Internal/RelationshipsSnapshot.cs @@ -98,7 +98,7 @@ private HashSet GetOrCreateCollection(int index) var snapshot = (HashSet?)_values[index]; if (snapshot == null) { - snapshot = new HashSet(LegacyReferenceEqualityComparer.Instance); + snapshot = new HashSet(ReferenceEqualityComparer.Instance); _values[index] = snapshot; } diff --git a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs index 112729c8681..6eaf3fd8052 100644 --- a/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs +++ b/src/EFCore/ChangeTracking/Internal/SnapshotFactoryFactory.cs @@ -268,5 +268,5 @@ protected virtual bool UseEntityVariable private static HashSet? SnapshotCollection(IEnumerable? collection) => collection == null ? null - : new HashSet(collection, LegacyReferenceEqualityComparer.Instance); + : new HashSet(collection, ReferenceEqualityComparer.Instance); } diff --git a/src/EFCore/ChangeTracking/Internal/StateManager.cs b/src/EFCore/ChangeTracking/Internal/StateManager.cs index b4f08bf7850..6966c5b2361 100644 --- a/src/EFCore/ChangeTracking/Internal/StateManager.cs +++ b/src/EFCore/ChangeTracking/Internal/StateManager.cs @@ -740,7 +740,7 @@ public virtual void AbortAttachGraph() InternalEntityEntry referencedFromEntry) { _referencedUntrackedEntities ??= - new Dictionary>>(LegacyReferenceEqualityComparer.Instance); + new Dictionary>>(ReferenceEqualityComparer.Instance); if (!_referencedUntrackedEntities.TryGetValue(referencedEntity, out var danglers)) { diff --git a/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs b/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs index 4da6686a02f..235726c192a 100644 --- a/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs +++ b/src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs @@ -257,7 +257,7 @@ private static bool IsObservableHashSet(Type type) where TCollection : class where TElement : class { - var collection = (TCollection)(ICollection)new HashSet(LegacyReferenceEqualityComparer.Instance); + var collection = (TCollection)(ICollection)new HashSet(ReferenceEqualityComparer.Instance); setterDelegate(entity, collection); return collection; } @@ -266,7 +266,7 @@ private static bool IsObservableHashSet(Type type) private static TCollection CreateHashSet() where TCollection : class where TElement : class - => (TCollection)(ICollection)new HashSet(LegacyReferenceEqualityComparer.Instance); + => (TCollection)(ICollection)new HashSet(ReferenceEqualityComparer.Instance); [UsedImplicitly] private static TCollection CreateAndSetObservableHashSet( @@ -276,7 +276,7 @@ private static bool IsObservableHashSet(Type type) where TCollection : class where TElement : class { - var collection = (TCollection)(ICollection)new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + var collection = (TCollection)(ICollection)new ObservableHashSet(ReferenceEqualityComparer.Instance); setterDelegate(entity, collection); return collection; } @@ -285,5 +285,5 @@ private static bool IsObservableHashSet(Type type) private static TCollection CreateObservableHashSet() where TCollection : class where TElement : class - => (TCollection)(ICollection)new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + => (TCollection)(ICollection)new ObservableHashSet(ReferenceEqualityComparer.Instance); } diff --git a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs index 45115fbb5b8..2267274cf5a 100644 --- a/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs +++ b/src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs @@ -3610,7 +3610,7 @@ private static InternalForeignKeyBuilder MergeFacetsFrom(Navigation newNavigatio } } - if (dependentEntityType.GetForeignKeys().Contains(Metadata, LegacyReferenceEqualityComparer.Instance)) + if (dependentEntityType.GetForeignKeys().Contains(Metadata, ReferenceEqualityComparer.Instance)) { Check.DebugAssert(Metadata.IsInModel, "Metadata isn't in the model"); diff --git a/src/Shared/ReferenceEqualityComparer.cs b/src/Shared/ReferenceEqualityComparer.cs deleted file mode 100644 index 5e685ad4f09..00000000000 --- a/src/Shared/ReferenceEqualityComparer.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -#nullable enable - -using System.Collections; -using System.Collections.Generic; -using System.Runtime.CompilerServices; - -#pragma warning disable RS1024 // Compare symbols correctly (for Roslyn analyzers only) - -namespace Microsoft.EntityFrameworkCore.Internal; - -internal sealed class LegacyReferenceEqualityComparer : IEqualityComparer, IEqualityComparer -{ - private LegacyReferenceEqualityComparer() - { - } - - public static LegacyReferenceEqualityComparer Instance { get; } = new(); - - public new bool Equals(object? x, object? y) - => ReferenceEquals(x, y); - - public int GetHashCode(object obj) - => RuntimeHelpers.GetHashCode(obj); - - bool IEqualityComparer.Equals(object? x, object? y) - => ReferenceEquals(x, y); - - int IEqualityComparer.GetHashCode(object obj) - => RuntimeHelpers.GetHashCode(obj); - - bool IEqualityComparer.Equals(object? x, object? y) - => ReferenceEquals(x, y); - - int IEqualityComparer.GetHashCode(object obj) - => RuntimeHelpers.GetHashCode(obj); -} diff --git a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs index d4982bc66b1..4aa984a11e5 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeNoTrackingQueryTestBase.cs @@ -57,7 +57,7 @@ var customer .AsNoTracking() .Single(c => c.CustomerID == "ALFKI"); - Assert.NotEqual(orders, customer.Orders, LegacyReferenceEqualityComparer.Instance); + Assert.NotEqual(orders, customer.Orders, ReferenceEqualityComparer.Instance); Assert.Equal(6, customer.Orders.Count); Assert.True(customer.Orders.All(e => ReferenceEquals(e.Customer, customer))); diff --git a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs index 08f3a63f620..747b26628e3 100644 --- a/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs +++ b/test/EFCore.Relational.Specification.Tests/Query/NorthwindSplitIncludeQueryTestBase.cs @@ -54,7 +54,7 @@ var customer .AsSplitQuery() .Single(c => c.CustomerID == "ALFKI"); - Assert.Equal(orders, customer.Orders, LegacyReferenceEqualityComparer.Instance); + Assert.Equal(orders, customer.Orders, ReferenceEqualityComparer.Instance); Assert.Equal(6, customer.Orders.Count); Assert.True(orders.All(o => ReferenceEquals(o.Customer, customer))); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); diff --git a/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBase.cs b/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBase.cs index 8519cfe7955..27ab87f1a66 100644 --- a/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBase.cs +++ b/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBase.cs @@ -544,28 +544,28 @@ protected virtual object CreateFullGraph() { AlternateId = RootAK, RequiredChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() } + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() } }, - new() { Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() } } + new() { Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() } } }, OptionalChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() }, + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() }, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) }, new() { - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() }, + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() }, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) } }, RequiredSingle = new RequiredSingle1 { Single = new RequiredSingle2() }, @@ -583,51 +583,51 @@ protected virtual object CreateFullGraph() DerivedRoot = new Root() }, RequiredChildrenAk = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { AlternateId = Guid.NewGuid(), - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { AlternateId = Guid.NewGuid() }, new() { AlternateId = Guid.NewGuid() } }, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() } + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() } }, new() { AlternateId = Guid.NewGuid(), - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { AlternateId = Guid.NewGuid() }, new() { AlternateId = Guid.NewGuid() } }, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() } + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() } } }, OptionalChildrenAk = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { AlternateId = Guid.NewGuid(), - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { AlternateId = Guid.NewGuid() }, new() { AlternateId = Guid.NewGuid() } }, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() } + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() } }, new() { AlternateId = Guid.NewGuid(), - Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { AlternateId = Guid.NewGuid() }, new() { AlternateId = Guid.NewGuid() } }, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { new(), new() } + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new(), new() } } }, RequiredSingleAk = @@ -674,13 +674,13 @@ protected virtual object CreateFullGraph() Root = new Root(), DerivedRoot = new Root() }, - RequiredCompositeChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + RequiredCompositeChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { Id = 1, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { Id = 1 }, new() { Id = 2 } } @@ -689,7 +689,7 @@ protected virtual object CreateFullGraph() { Id = 2, CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { Id = 3 }, new() { Id = 4 } } @@ -1146,8 +1146,8 @@ protected class Root : NotifyingEntity { private int _id; private Guid _alternateId; - private IEnumerable _requiredChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); - private IEnumerable _optionalChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private IEnumerable _requiredChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance); + private IEnumerable _optionalChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance); private RequiredSingle1 _requiredSingle; private RequiredNonPkSingle1 _requiredNonPkSingle; private RequiredNonPkSingle1Derived _requiredNonPkSingleDerived; @@ -1157,10 +1157,10 @@ protected class Root : NotifyingEntity private OptionalSingle1MoreDerived _optionalSingleMoreDerived; private IEnumerable _requiredChildrenAk = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); private IEnumerable _optionalChildrenAk = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); private RequiredSingleAk1 _requiredSingleAk; private RequiredNonPkSingleAk1 _requiredNonPkSingleAk; @@ -1171,7 +1171,7 @@ protected class Root : NotifyingEntity private OptionalSingleAk1MoreDerived _optionalSingleAkMoreDerived; private IEnumerable _requiredCompositeChildren - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -1314,7 +1314,7 @@ protected class Required1 : NotifyingEntity private int _id; private int _parentId; private Root _parent; - private IEnumerable _children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private IEnumerable _children = new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -1425,10 +1425,10 @@ protected class Optional1 : NotifyingEntity private int _id; private int? _parentId; private Root _parent; - private IEnumerable _children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private IEnumerable _children = new ObservableHashSet(ReferenceEqualityComparer.Instance); private ICollection _compositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -1926,10 +1926,10 @@ protected class RequiredAk1 : NotifyingEntity private Guid _alternateId; private Guid _parentId; private Root _parent; - private IEnumerable _children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private IEnumerable _children = new ObservableHashSet(ReferenceEqualityComparer.Instance); private IEnumerable _compositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -2043,7 +2043,7 @@ protected class RequiredComposite1 : NotifyingEntity private Root _parent; private ICollection _compositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -2192,10 +2192,10 @@ protected class OptionalAk1 : NotifyingEntity private Guid _alternateId; private Guid? _parentId; private Root _parent; - private IEnumerable _children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private IEnumerable _children = new ObservableHashSet(ReferenceEqualityComparer.Instance); private ICollection _compositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -2874,7 +2874,7 @@ protected class BadCustomer : NotifyingEntity { private int _id; private int _status; - private ICollection _badOrders = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private ICollection _badOrders = new ObservableHashSet(ReferenceEqualityComparer.Instance); public int Id { @@ -3007,7 +3007,7 @@ public ParentAsAChild ParentAsAChild protected abstract class TaskWithChoices : QuestTask { - private ICollection _choices = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private ICollection _choices = new ObservableHashSet(ReferenceEqualityComparer.Instance); public ICollection Choices { @@ -3044,7 +3044,7 @@ public int BarCode protected class Bloog : NotifyingEntity { private int _id; - private IEnumerable _poosts = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + private IEnumerable _poosts = new ObservableHashSet(ReferenceEqualityComparer.Instance); [DatabaseGenerated(DatabaseGeneratedOption.None)] public int Id @@ -3091,10 +3091,10 @@ protected class SharedFkRoot : NotifyingEntity private long _id; private ICollection _dependants - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); private ICollection _parents - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public long Id { diff --git a/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBaseOneToMany.cs b/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBaseOneToMany.cs index 70d3e290768..4c3b220bcba 100644 --- a/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBaseOneToMany.cs +++ b/test/EFCore.Specification.Tests/GraphUpdates/GraphUpdatesTestBaseOneToMany.cs @@ -695,7 +695,7 @@ public abstract partial class GraphUpdatesTestBase { newParent = new Optional1 { - CompositeChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + CompositeChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) }; context.Set().Add(newParent); @@ -1120,7 +1120,7 @@ public abstract partial class GraphUpdatesTestBase { Id = 3, Parent = context.Set().Single(IsTheRoot), - CompositeChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + CompositeChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) { new() { Id = 5 }, new() { Id = 6 } } diff --git a/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesFixtureBase.cs b/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesFixtureBase.cs index de8dbfbcace..e86cfc853c8 100644 --- a/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesFixtureBase.cs +++ b/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesFixtureBase.cs @@ -396,12 +396,12 @@ protected virtual object CreateFullGraph(DbContext context) { e.AlternateId = RootAK; - e.RequiredChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.RequiredChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.CreateProxy( e => { - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; @@ -409,36 +409,36 @@ protected virtual object CreateFullGraph(DbContext context) context.CreateProxy( e => { - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; }) }; - e.OptionalChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.OptionalChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy( e => { - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); }), context.Set().CreateProxy( e => { - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + new ObservableHashSet(ReferenceEqualityComparer.Instance); }) }; @@ -472,21 +472,21 @@ protected virtual object CreateFullGraph(DbContext context) e.DerivedRoot = context.Set().CreateProxy(); }); - e.RequiredChildrenAk = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.RequiredChildrenAk = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy( e => { e.AlternateId = Guid.NewGuid(); - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()), context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()) }; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; @@ -496,34 +496,34 @@ protected virtual object CreateFullGraph(DbContext context) { e.AlternateId = Guid.NewGuid(); - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()), context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()) }; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; }) }; - e.OptionalChildrenAk = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.OptionalChildrenAk = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy( e => { e.AlternateId = Guid.NewGuid(); - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()), context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()) }; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; @@ -533,14 +533,14 @@ protected virtual object CreateFullGraph(DbContext context) { e.AlternateId = Guid.NewGuid(); - e.Children = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.Children = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()), context.Set().CreateProxy(e => e.AlternateId = Guid.NewGuid()) }; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy(), context.Set().CreateProxy() }; @@ -601,7 +601,7 @@ protected virtual object CreateFullGraph(DbContext context) e.DerivedRoot = context.CreateProxy(); }); - e.RequiredCompositeChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.RequiredCompositeChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.Set().CreateProxy( e => @@ -609,7 +609,7 @@ protected virtual object CreateFullGraph(DbContext context) e.Id = 1; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.CreateProxy(e => e.Id = 1), context.CreateProxy(e => e.Id = 2) @@ -621,7 +621,7 @@ protected virtual object CreateFullGraph(DbContext context) e.Id = 2; e.CompositeChildren = - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.CreateProxy(e => e.Id = 3), context.CreateProxy(e => e.Id = 4) @@ -801,10 +801,10 @@ protected Root() public virtual Guid AlternateId { get; set; } public virtual IEnumerable RequiredChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual IEnumerable OptionalChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual RequiredSingle1 RequiredSingle { get; set; } @@ -821,10 +821,10 @@ protected Root() public virtual OptionalSingle1MoreDerived OptionalSingleMoreDerived { get; set; } public virtual IEnumerable RequiredChildrenAk { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual IEnumerable OptionalChildrenAk { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual RequiredSingleAk1 RequiredSingleAk { get; set; } @@ -841,7 +841,7 @@ protected Root() public virtual OptionalSingleAk1MoreDerived OptionalSingleAkMoreDerived { get; set; } public virtual IEnumerable RequiredCompositeChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public override bool Equals(object obj) { @@ -866,7 +866,7 @@ protected Required1() public virtual Root Parent { get; set; } public virtual IEnumerable Children { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public override bool Equals(object obj) { @@ -965,10 +965,10 @@ protected Optional1() public virtual Root Parent { get; set; } public virtual IEnumerable Children { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual ICollection CompositeChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public override bool Equals(object obj) { @@ -1323,10 +1323,10 @@ protected RequiredAk1() public virtual Root Parent { get; set; } public virtual IEnumerable Children { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual IEnumerable CompositeChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public override bool Equals(object obj) { @@ -1407,7 +1407,7 @@ public override bool Equals(object obj) } public virtual ICollection CompositeChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public override int GetHashCode() => Id; @@ -1504,10 +1504,10 @@ protected OptionalAk1() public virtual Root Parent { get; set; } public virtual IEnumerable Children { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public virtual ICollection CompositeChildren { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); public override bool Equals(object obj) { @@ -1956,7 +1956,7 @@ protected BadCustomer() public virtual int Status { get; set; } public virtual ICollection BadOrders { get; set; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); } public class BadOrder @@ -2022,7 +2022,7 @@ public record RecordCar : RecordBase public record RecordPerson : RecordBase { public virtual ICollection Vehicles { get; } - = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance); + = new ObservableHashSet(ReferenceEqualityComparer.Instance); } protected DbContext CreateContext() diff --git a/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesTestBaseOneToMany.cs b/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesTestBaseOneToMany.cs index 3c0deebc6c6..36b15edf072 100644 --- a/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesTestBaseOneToMany.cs +++ b/test/EFCore.Specification.Tests/GraphUpdates/ProxyGraphUpdatesTestBaseOneToMany.cs @@ -463,7 +463,7 @@ public virtual void Reparent_to_different_one_to_many(ChangeMechanism changeMech if (!useExistingParent) { newParent = context.CreateProxy( - e => e.CompositeChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance)); + e => e.CompositeChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance)); context.Set().Add(newParent); context.SaveChanges(); @@ -607,7 +607,7 @@ public virtual void Reparent_one_to_many_overlapping(ChangeMechanism changeMecha { e.Id = 3; e.Parent = context.Set().Single(IsTheRoot); - e.CompositeChildren = new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) + e.CompositeChildren = new ObservableHashSet(ReferenceEqualityComparer.Instance) { context.CreateProxy(e => e.Id = 5), context.CreateProxy(e => e.Id = 6) diff --git a/test/EFCore.Specification.Tests/Query/NorthwindEFPropertyIncludeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindEFPropertyIncludeQueryTestBase.cs index e24b06ac008..8175f6dd065 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindEFPropertyIncludeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindEFPropertyIncludeQueryTestBase.cs @@ -64,7 +64,7 @@ var customer .Include(c => EF.Property(c, "Orders")) .Single(c => c.CustomerID == "ALFKI"); - Assert.Equal(orders, customer.Orders, LegacyReferenceEqualityComparer.Instance); + Assert.Equal(orders, customer.Orders, ReferenceEqualityComparer.Instance); Assert.Equal(6, customer.Orders.Count); Assert.True(orders.All(o => ReferenceEquals(o.Customer, customer))); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindIncludeNoTrackingQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindIncludeNoTrackingQueryTestBase.cs index 51f6634392f..9c72c3aa17e 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindIncludeNoTrackingQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindIncludeNoTrackingQueryTestBase.cs @@ -129,7 +129,7 @@ var customer .AsNoTracking() .Single(c => c.CustomerID == "ALFKI"); - Assert.NotEqual(orders, customer.Orders, LegacyReferenceEqualityComparer.Instance); + Assert.NotEqual(orders, customer.Orders, ReferenceEqualityComparer.Instance); Assert.Equal(6, customer.Orders.Count); Assert.True(customer.Orders.All(e => ReferenceEquals(e.Customer, customer))); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs index bcfb27cefdc..2fc8ee0b8fc 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindIncludeQueryTestBase.cs @@ -245,7 +245,7 @@ var customer .Include(c => c.Orders) .Single(c => c.CustomerID == "ALFKI"); - Assert.Equal(orders, customer.Orders, LegacyReferenceEqualityComparer.Instance); + Assert.Equal(orders, customer.Orders, ReferenceEqualityComparer.Instance); Assert.Equal(6, customer.Orders.Count); Assert.True(orders.All(o => ReferenceEquals(o.Customer, customer))); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); diff --git a/test/EFCore.Specification.Tests/Query/NorthwindStringIncludeQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/NorthwindStringIncludeQueryTestBase.cs index 0db6bfb4c60..58dcc04c09c 100644 --- a/test/EFCore.Specification.Tests/Query/NorthwindStringIncludeQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/NorthwindStringIncludeQueryTestBase.cs @@ -89,7 +89,7 @@ var customer .Include("Orders") .Single(c => c.CustomerID == "ALFKI"); - Assert.Equal(orders, customer.Orders, LegacyReferenceEqualityComparer.Instance); + Assert.Equal(orders, customer.Orders, ReferenceEqualityComparer.Instance); Assert.Equal(6, customer.Orders.Count); Assert.True(orders.All(o => ReferenceEquals(o.Customer, customer))); Assert.Equal(6 + 1, context.ChangeTracker.Entries().Count()); diff --git a/test/EFCore.Specification.Tests/SerializationTestBase.cs b/test/EFCore.Specification.Tests/SerializationTestBase.cs index 6d63a5ca4fb..3c049fd6ec6 100644 --- a/test/EFCore.Specification.Tests/SerializationTestBase.cs +++ b/test/EFCore.Specification.Tests/SerializationTestBase.cs @@ -140,7 +140,7 @@ private static T RoundtripThroughNewtonsoftJson(T collection, bool ignoreLoop ReferenceLoopHandling = ignoreLoops ? ReferenceLoopHandling.Ignore : ReferenceLoopHandling.Error, - EqualityComparer = LegacyReferenceEqualityComparer.Instance, + EqualityComparer = ReferenceEqualityComparer.Instance, Formatting = writeIndented ? Formatting.Indented : Formatting.None diff --git a/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs b/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs index 5c166578b6f..4138fd1fcc0 100644 --- a/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs +++ b/test/EFCore.Tests/ChangeTracking/Internal/OwnedFixupTest.cs @@ -5583,8 +5583,8 @@ private static ICollection CreateChildCollection(CollectionType collection CollectionType.SortedSet => new SortedSet { dependent }, CollectionType.Collection => new Collection { dependent }, CollectionType.ObservableCollection => new ObservableCollection { dependent }, - CollectionType.ObservableHashSet => new ObservableHashSet(LegacyReferenceEqualityComparer.Instance) { dependent }, - _ => new HashSet(LegacyReferenceEqualityComparer.Instance) { dependent } + CollectionType.ObservableHashSet => new ObservableHashSet(ReferenceEqualityComparer.Instance) { dependent }, + _ => new HashSet(ReferenceEqualityComparer.Instance) { dependent } }; private void AssertFixup(DbContext context, Action asserts) diff --git a/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs b/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs index a3d8d8a79dc..744d43f3c96 100644 --- a/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs +++ b/test/EFCore.Tests/ChangeTracking/ObservableHashSetTest.cs @@ -20,8 +20,8 @@ public void Can_construct() new ObservableHashSet().Comparer); Assert.Same( - LegacyReferenceEqualityComparer.Instance, - new ObservableHashSet(LegacyReferenceEqualityComparer.Instance).Comparer); + ReferenceEqualityComparer.Instance, + new ObservableHashSet(ReferenceEqualityComparer.Instance).Comparer); var testData1 = CreateTestData(); @@ -32,8 +32,8 @@ public void Can_construct() var testData2 = CreateTestData().Cast(); - var rh2 = new HashSet(testData2, LegacyReferenceEqualityComparer.Instance); - var ohs2 = new ObservableHashSet(testData2, LegacyReferenceEqualityComparer.Instance); + var rh2 = new HashSet(testData2, ReferenceEqualityComparer.Instance); + var ohs2 = new ObservableHashSet(testData2, ReferenceEqualityComparer.Instance); Assert.Equal(rh2.OrderBy(i => i), ohs2.OrderBy(i => i)); Assert.Same(rh2.Comparer, ohs2.Comparer); } diff --git a/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs b/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs index c8ecf1cf3f7..843e83ea9a6 100644 --- a/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs +++ b/test/EFCore.Tests/Extensions/QueryableExtensionsTest.cs @@ -303,12 +303,12 @@ public async Task Extension_methods_throw_on_non_async_source() await SourceNonAsyncQueryableTest(() => Source().SumAsync(e => e)); await SourceNonAsyncEnumerableTest(() => Source().ToDictionaryAsync(e => e)); await SourceNonAsyncEnumerableTest(() => Source().ToDictionaryAsync(e => e, e => e)); - await SourceNonAsyncEnumerableTest(() => Source().ToDictionaryAsync(e => e, LegacyReferenceEqualityComparer.Instance)); - await SourceNonAsyncEnumerableTest(() => Source().ToDictionaryAsync(e => e, LegacyReferenceEqualityComparer.Instance)); + await SourceNonAsyncEnumerableTest(() => Source().ToDictionaryAsync(e => e, ReferenceEqualityComparer.Instance)); + await SourceNonAsyncEnumerableTest(() => Source().ToDictionaryAsync(e => e, ReferenceEqualityComparer.Instance)); await SourceNonAsyncEnumerableTest( - () => Source().ToDictionaryAsync(e => e, e => e, LegacyReferenceEqualityComparer.Instance)); + () => Source().ToDictionaryAsync(e => e, e => e, ReferenceEqualityComparer.Instance)); await SourceNonAsyncEnumerableTest( - () => Source().ToDictionaryAsync(e => e, e => e, LegacyReferenceEqualityComparer.Instance, new CancellationToken())); + () => Source().ToDictionaryAsync(e => e, e => e, ReferenceEqualityComparer.Instance, new CancellationToken())); await SourceNonAsyncEnumerableTest(() => Source().ToListAsync()); Assert.Equal(