public virtual bool Equals(Entity other) { if (ReferenceEquals(other, null)) { return(false); } if (ReferenceEquals(other, this)) { return(true); } var thisId = Id; var otherId = other.Id; //If both objects aren't transient and ids are same, they are equal only if the type are the same if (!IsTransient(this) && !IsTransient(other) && Equals(thisId, otherId)) { var thisType = GetUnproxiedType(); var otherType = other.GetUnproxiedType(); //If they are same type they are equal since Ids are identicay for non-transient objects. // If using incompatible types, e.g. using Equals(DerivedB, DerivedA), IsAssignableFrom will return false. return(thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType)); } return(false); }
public virtual bool Equals(Entity other) { if (ReferenceEquals(other, null)) return false; if (ReferenceEquals(other, this)) return true; var thisId = Id; var otherId = other.Id; if (!IsTransient(this) && !IsTransient(other) && Equals(thisId, otherId)) { var thisType = GetUnproxiedType(); var otherType = other.GetUnproxiedType(); return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType); } return false; }
public virtual bool Equals(Entity <TId> other) { if (other == null) { return(false); } if (ReferenceEquals(this, other)) { return(true); } if (!IsTransient(this) && !IsTransient(other) && Equals(ID, other.ID)) { var otherType = other.GetUnproxiedType(); var thisType = GetUnproxiedType(); return(thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType)); } return(false); }
public virtual bool Equals(Entity other) { if (ReferenceEquals(other, null)) return false; if (ReferenceEquals(other, this)) return true; var thisId = Id; var otherId = other.Id; //If both objects aren't transient and ids are same, they are equal only if the type are the same if (!IsTransient(this) && !IsTransient(other) && Equals(thisId, otherId)) { var thisType = GetUnproxiedType(); var otherType = other.GetUnproxiedType(); //If they are same type they are equal since Ids are identicay for non-transient objects. // If using incompatible types, e.g. using Equals(DerivedB, DerivedA), IsAssignableFrom will return false. return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType); } return false; }