public override bool Equals(object obj)
        {
            //obj不为空
            if (obj == null)
                return false;
            //是否同一个引用
            if (ReferenceEquals(this, obj))
                return true;
            //是否不是聚合根
            IAggregateRoot ar = obj as IAggregateRoot;
            if (ar == null)
                return false;
            //是否不是同一个类型
            var thisType = this.GetType().Namespace.StartsWith("System.Data.Entity.Dynamic") ? this.GetType().BaseType : this.GetType();
            var objType = obj.GetType().Namespace.StartsWith("System.Data.Entity.Dynamic") ? obj.GetType().BaseType : obj.GetType();
            if (thisType != objType)
            {
                return false;
            }

            //Id是否相等
            return this.Id == ar.Id;
        }

        public override int GetHashCode()
        {
           var thisType = this.GetType().Namespace.StartsWith("System.Data.Entity.Dynamic") ? this.GetType().BaseType : this.GetType();
           string keyword = thisType.FullName + "|" + this.Id;
           return keyword.GetHashCode();
           //return this.Id.GetHashCode();
           //return base.GetHashCode();
        }

 

相关文章:

  • 2021-06-09
  • 2021-10-27
  • 2022-01-31
  • 2021-09-03
  • 2021-12-31
  • 2021-11-06
  • 2021-10-02
  • 2021-10-14
猜你喜欢
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-13
相关资源
相似解决方案