How do I get the entity type on an object that may be a NHibernate proxy object?

后端 未结 4 852
独厮守ぢ
独厮守ぢ 2021-02-19 04:21

I have a base class DomainObject for all my business objects I am using with NHibernate. It contains the Id property.

public abstract          


        
4条回答
  •  面向向阳花
    2021-02-19 05:06

    i took a different aproach in a production project. I simply have a global HiLow Id-Generator which generates Id's unique for all types then i can:

    // in DomainEntity
    public override bool Equals(object obj)
    {
        var other = obj as DomainEntity;
        if (Id == 0) // IsTransient()
            return ReferenceEquals(this, other);
        else
            return (other != null) && (Id == other.Id);
    }
    
    // Comparer
    bool IEqualityComparer.Equals(object x, object y)
    {
        return object.Equals(x, y);
    }
    

提交回复
热议问题