Skip to content

Commit

Permalink
Remove LegacyReferenceEqualityComparer
Browse files Browse the repository at this point in the history
Fixes #29428
  • Loading branch information
ajcvickers committed Dec 8, 2022
1 parent cc1e54a commit 135fca6
Show file tree
Hide file tree
Showing 26 changed files with 115 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public virtual void Intercept(IInvocation invocation)

if (navigation != null)
{
HandleChanged(invocation, navigation, LegacyReferenceEqualityComparer.Instance);
HandleChanged(invocation, navigation, ReferenceEqualityComparer.Instance);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public virtual void Intercept(IInvocation invocation)

if (navigation != null)
{
HandleChanging(invocation, navigation, LegacyReferenceEqualityComparer.Instance);
HandleChanging(invocation, navigation, ReferenceEqualityComparer.Instance);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.EntityFrameworkCore.Query.Internal;
public class FromSqlParameterExpandingExpressionVisitor : ExpressionVisitor
{
private readonly IDictionary<FromSqlExpression, Expression> _visitedFromSqlExpressions
= new Dictionary<FromSqlExpression, Expression>(LegacyReferenceEqualityComparer.Instance);
= new Dictionary<FromSqlExpression, Expression>(ReferenceEqualityComparer.Instance);

private readonly ISqlExpressionFactory _sqlExpressionFactory;
private readonly IRelationalTypeMappingSource _typeMappingSource;
Expand Down
4 changes: 2 additions & 2 deletions src/EFCore/ChangeTracking/Internal/ChangeDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public bool DetectNavigationChange(InternalEntityEntry entry, INavigationBase na
var snapshotCollection = (IEnumerable?)snapshotValue;
var currentCollection = (IEnumerable?)currentValue;

var removed = new HashSet<object>(LegacyReferenceEqualityComparer.Instance);
var removed = new HashSet<object>(ReferenceEqualityComparer.Instance);
if (snapshotCollection != null)
{
foreach (var entity in snapshotCollection)
Expand All @@ -343,7 +343,7 @@ public bool DetectNavigationChange(InternalEntityEntry entry, INavigationBase na
}
}

var added = new HashSet<object>(LegacyReferenceEqualityComparer.Instance);
var added = new HashSet<object>(ReferenceEqualityComparer.Instance);
if (currentCollection != null)
{
foreach (var entity in currentCollection)
Expand Down
10 changes: 5 additions & 5 deletions src/EFCore/ChangeTracking/Internal/EntityReferenceMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,24 @@ public EntityReferenceMap(bool hasSubMap)
switch (state)
{
case EntityState.Detached:
_detachedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(LegacyReferenceEqualityComparer.Instance);
_detachedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(ReferenceEqualityComparer.Instance);
_detachedReferenceMap[mapKey] = entry;
break;
case EntityState.Unchanged:
_unchangedReferenceMap ??=
new Dictionary<object, InternalEntityEntry>(LegacyReferenceEqualityComparer.Instance);
new Dictionary<object, InternalEntityEntry>(ReferenceEqualityComparer.Instance);
_unchangedReferenceMap[mapKey] = entry;
break;
case EntityState.Deleted:
_deletedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(LegacyReferenceEqualityComparer.Instance);
_deletedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(ReferenceEqualityComparer.Instance);
_deletedReferenceMap[mapKey] = entry;
break;
case EntityState.Modified:
_modifiedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(LegacyReferenceEqualityComparer.Instance);
_modifiedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(ReferenceEqualityComparer.Instance);
_modifiedReferenceMap[mapKey] = entry;
break;
case EntityState.Added:
_addedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(LegacyReferenceEqualityComparer.Instance);
_addedReferenceMap ??= new Dictionary<object, InternalEntityEntry>(ReferenceEqualityComparer.Instance);
_addedReferenceMap[mapKey] = entry;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/IdentityMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private void Add(TKey key, InternalEntityEntry entry, bool updateDuplicate)
/// </summary>
public virtual IDependentsMap GetDependentsMap(IForeignKey foreignKey)
{
_dependentMaps ??= new Dictionary<IForeignKey, IDependentsMap>(LegacyReferenceEqualityComparer.Instance);
_dependentMaps ??= new Dictionary<IForeignKey, IDependentsMap>(ReferenceEqualityComparer.Instance);

if (!_dependentMaps.TryGetValue(foreignKey, out var map))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private HashSet<object> GetOrCreateCollection(int index)
var snapshot = (HashSet<object>?)_values[index];
if (snapshot == null)
{
snapshot = new HashSet<object>(LegacyReferenceEqualityComparer.Instance);
snapshot = new HashSet<object>(ReferenceEqualityComparer.Instance);
_values[index] = snapshot;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,5 +268,5 @@ protected virtual bool UseEntityVariable
private static HashSet<object>? SnapshotCollection(IEnumerable<object>? collection)
=> collection == null
? null
: new HashSet<object>(collection, LegacyReferenceEqualityComparer.Instance);
: new HashSet<object>(collection, ReferenceEqualityComparer.Instance);
}
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/Internal/StateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ public virtual void AbortAttachGraph()
InternalEntityEntry referencedFromEntry)
{
_referencedUntrackedEntities ??=
new Dictionary<object, IList<Tuple<INavigationBase, InternalEntityEntry>>>(LegacyReferenceEqualityComparer.Instance);
new Dictionary<object, IList<Tuple<INavigationBase, InternalEntityEntry>>>(ReferenceEqualityComparer.Instance);

if (!_referencedUntrackedEntities.TryGetValue(referencedEntity, out var danglers))
{
Expand Down
8 changes: 4 additions & 4 deletions src/EFCore/Metadata/Internal/ClrCollectionAccessorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private static bool IsObservableHashSet(Type type)
where TCollection : class
where TElement : class
{
var collection = (TCollection)(ICollection<TElement>)new HashSet<TElement>(LegacyReferenceEqualityComparer.Instance);
var collection = (TCollection)(ICollection<TElement>)new HashSet<TElement>(ReferenceEqualityComparer.Instance);
setterDelegate(entity, collection);
return collection;
}
Expand All @@ -266,7 +266,7 @@ private static bool IsObservableHashSet(Type type)
private static TCollection CreateHashSet<TCollection, TElement>()
where TCollection : class
where TElement : class
=> (TCollection)(ICollection<TElement>)new HashSet<TElement>(LegacyReferenceEqualityComparer.Instance);
=> (TCollection)(ICollection<TElement>)new HashSet<TElement>(ReferenceEqualityComparer.Instance);

[UsedImplicitly]
private static TCollection CreateAndSetObservableHashSet<TEntity, TCollection, TElement>(
Expand All @@ -276,7 +276,7 @@ private static bool IsObservableHashSet(Type type)
where TCollection : class
where TElement : class
{
var collection = (TCollection)(ICollection<TElement>)new ObservableHashSet<TElement>(LegacyReferenceEqualityComparer.Instance);
var collection = (TCollection)(ICollection<TElement>)new ObservableHashSet<TElement>(ReferenceEqualityComparer.Instance);
setterDelegate(entity, collection);
return collection;
}
Expand All @@ -285,5 +285,5 @@ private static bool IsObservableHashSet(Type type)
private static TCollection CreateObservableHashSet<TCollection, TElement>()
where TCollection : class
where TElement : class
=> (TCollection)(ICollection<TElement>)new ObservableHashSet<TElement>(LegacyReferenceEqualityComparer.Instance);
=> (TCollection)(ICollection<TElement>)new ObservableHashSet<TElement>(ReferenceEqualityComparer.Instance);
}
2 changes: 1 addition & 1 deletion src/EFCore/Metadata/Internal/InternalForeignKeyBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down
39 changes: 0 additions & 39 deletions src/Shared/ReferenceEqualityComparer.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading

0 comments on commit 135fca6

Please sign in to comment.