nhibernate / nhibernate-core

NHibernate Object Relational Mapper
https://nhibernate.info
GNU Lesser General Public License v2.1
2.11k stars 921 forks source link

Why use "RootEntityName" compare, not use "EntityName" inNHibernate/Engine /EntityKey.Equals0 #3471

Closed Lio98 closed 5 months ago

Lio98 commented 5 months ago

NHibernate.Engine.EntityKey.cs

        public bool Equals(EntityKey other)
        {
            if (other == null)
            {
                return false;
            }

            return
                other.RootEntityName.Equals(RootEntityName)
                && _persister.IdentifierType.IsEqual(other.Identifier, Identifier, _persister.Factory);
        }
fredericDelaporte commented 5 months ago

Because that is the right thing to do.

https://github.com/nhibernate/nhibernate-core/blob/07c367fb859086970737c35f24fe66c089a034e2/src/NHibernate/Persister/Entity/IEntityPersister.cs#L36-L40

Why should we use the EntityName? In case we have a key from a proxy of a base class, we would no more be able to infer that is actually the key points the same entity than a key of the entity loaded from its concrete type.