public override bool Equals(object rhs) { BusinessBase <T> other = rhs as BusinessBase <T>; if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (!IsTransient(this) && !IsTransient(other) && Id.Equals(other.Id)) { var otherType = other.GetUnproxiedType(); var thisType = GetUnproxiedType(); return(thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType)); } return(false); }
/// <summary> /// Checks if an object is transient i.e an object yet to be associated with nHibernate proxy. /// An object is transient if, Id has default value. i.e. 0. /// </summary> /// <param name="obj">object for which the check is made.</param> /// <returns>true if transient object, else false.</returns> private static bool IsTransient(BusinessBase <T> obj) { return(obj != null && Equals(obj.Id, default(T))); }
/// <summary> /// Transient objects are not associated with an /// item already in storage. For instance, a /// Customer is transient if its ID is 0. /// </summary> public virtual bool IsTransient() { return(BusinessBase <T> .IsTransient(this)); }