Skip to content

Commit b8cc5c7

Browse files
committed
Implemented IEquatable<EntityKey>
1 parent c1e7d96 commit b8cc5c7

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/NHibernate/Engine/EntityKey.cs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace NHibernate.Engine
1212
/// and the identifier space (eg. tablename)
1313
/// </summary>
1414
[Serializable]
15-
public sealed class EntityKey : IDeserializationCallback, ISerializable
15+
public sealed class EntityKey : IDeserializationCallback, ISerializable, IEquatable<EntityKey>
1616
{
1717
private readonly object identifier;
1818
private readonly IEntityPersister _persister;
@@ -49,12 +49,19 @@ public object Identifier
4949

5050
public override bool Equals(object other)
5151
{
52-
var otherKey = other as EntityKey;
53-
if(otherKey==null) return false;
52+
return other is EntityKey otherKey && Equals(otherKey);
53+
}
54+
55+
public bool Equals(EntityKey other)
56+
{
57+
if (other == null)
58+
{
59+
return false;
60+
}
5461

5562
return
56-
otherKey.RootEntityName.Equals(RootEntityName)
57-
&& _persister.IdentifierType.IsEqual(otherKey.Identifier, Identifier, _persister.Factory);
63+
other.RootEntityName.Equals(RootEntityName)
64+
&& _persister.IdentifierType.IsEqual(other.Identifier, Identifier, _persister.Factory);
5865
}
5966

6067
public override int GetHashCode()

0 commit comments

Comments
 (0)