GetHashCode实现类

时间:2016-10-22 21:36:49

标签: c# gethashcode iequalitycomparer

我需要与Gu45Entity

的列表进行比较
List<Gu45Entity> Gu45EntityItemsFromDb = DataBaseModel.Instance.Gu45DocumentStore.Include(x => x.EGu45.Gu45).ToList();
List<Gu45Entity> temp = Gu45EntityItemsFormService.Except(Gu45EntityItemsFromDb).ToList();

如果我理解正确,我需要为每个班级实施IEqualityComparer<T>。但是在我的情况下应该如何GetHashCode实施Gu45Id不应包含在比较中,因为它是由数据库生成的随机数。

public class Gu45 : IEqualityComparer<Gu45>
{
    [Key]
    public int Id { get; set; }
    public Branch Branch { get; set; }
    public Direction Direction { get; set; }
    public Org Org { get; set; }
    public Wagons Wagons { get; set; }
    public string Num { get; set; }
    public string Date { get; set; }
    public string Esr_mount { get; set; }
    public string Esr_mount_name { get; set; }
    public string Rw_mount_name { get; set; }
    public string Delivery_time { get; set; }
    public string Taking_time { get; set; }
    public string Sign { get; set; }

    public bool Equals(Gu45 x, Gu45 y)
    {
        throw new NotImplementedException();
    }

    public int GetHashCode(Gu45 obj)
    {
        throw new NotImplementedException();
    }
}

类:

Gu45Entity:

public class Gu45Entity
{
    [Key]
    public int Id { get; set; }
    public EGu45 EGu45 { get; set; }
}

Egu45:

public class EGu45
{
    [Key]
    public int Id { get; set; }
    public Gu45 Gu45 { get; set; }
    public string Signature { get; set; }
    public string DocState { get; set; }
}

Gu45:

public class Gu45
{
    [Key]
    public int Id { get; set; }
    public Branch Branch { get; set; }
    public Direction Direction { get; set; }
    public Org Org { get; set; }
    public Wagons Wagons { get; set; }
    public string Num { get; set; }
    public string Date { get; set; }
    public string Esr_mount { get; set; }
    public string Esr_mount_name { get; set; }
    public string Rw_mount_name { get; set; }
    public string Delivery_time { get; set; }
    public string Taking_time { get; set; }
    public string Sign { get; set; }
}

科:

public class Branch
{
    [Key]
    public int Id { get; set; }
    public string Code { get; set; }
    public string Name { get; set; }
}

货车:

public class Wagons
{
    [Key]
    public int Id { get; set; }
    public Wagon Wagon { get; set; }
}

Direction,Branch,Org,......等。

0 个答案:

没有答案