public virtual bool Equals(BaseEntity other) { if (other == null) return false; if (ReferenceEquals(this, other)) return true; if (!IsTransient(this) && !IsTransient(other) && Id == other.Id) { var otherType = other.GetType(); var thisType = GetType(); return thisType.IsAssignableFrom(otherType) || otherType.IsAssignableFrom(thisType); } return false; }
private static bool IsTransient(BaseEntity obj) { return obj != null && obj.Id == null; }