public virtual bool Equals(BaseEntity 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; }
/// <summary> /// 判断实体对象是否是一个瞬时对象 /// </summary> /// <param name="obj"></param> /// <returns></returns> private static bool IsTransient(BaseEntity obj) { return obj != null && Equals(obj.Id, default(int)); }