Skip to content

Commit 1006665

Browse files
committed
Use reference entity comparison
1 parent ec89837 commit 1006665

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/NHibernate/Collection/AbstractPersistentCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ protected virtual ICollection GetOrphans(ICollection oldElements, ICollection cu
726726
return oldElements;
727727
}
728728

729-
if (currentElements.Count == oldElements.Count && currentElements.Cast<object>().SequenceEqual(oldElements.Cast<object>()))
729+
if (currentElements.Count == oldElements.Count && currentElements.Cast<object>().SequenceEqual(oldElements.Cast<object>(), ReferenceComparer<object>.Instance))
730730
return Array.Empty<object>();
731731

732732
var persister = session.Factory.GetEntityPersister(entityName);
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
5+
namespace NHibernate.Util
6+
{
7+
/// <summary>
8+
/// Compares objects by reference equality
9+
/// </summary>
10+
/// <typeparam name="T"></typeparam>
11+
[Serializable]
12+
class ReferenceComparer<T> : IEqualityComparer, IEqualityComparer<T> where T : class
13+
{
14+
private ReferenceComparer()
15+
{
16+
}
17+
18+
public bool Equals(T x, T y)
19+
{
20+
return ReferenceEquals(x, y);
21+
}
22+
23+
public int GetHashCode(T obj)
24+
{
25+
return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(obj);
26+
}
27+
28+
bool IEqualityComparer.Equals(object x, object y)
29+
{
30+
return ReferenceEquals(x, y);
31+
}
32+
33+
int IEqualityComparer.GetHashCode(object obj)
34+
{
35+
return System.Runtime.CompilerServices.RuntimeHelpers.GetHashCode(obj);
36+
}
37+
38+
public static readonly ReferenceComparer<T> Instance = new ReferenceComparer<T>();
39+
}
40+
}

0 commit comments

Comments
 (0)