0

I need to compare to List's of Gu45Entity

List<Gu45Entity> Gu45EntityItemsFromDb = DataBaseModel.Instance.Gu45DocumentStore.Include(x => x.EGu45.Gu45).ToList();
List<Gu45Entity> temp = Gu45EntityItemsFormService.Except(Gu45EntityItemsFromDb).ToList();

If I understand correctly I need to implement IEqualityComparer<T> For every class. But how in my case should be implemented GetHashCodefor example to Gu45 . Id should not include in the comparison because it's random number generated by database.

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();
    }
}

Classes:

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; }
}

Branch:

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

Wagons:

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

Direction,Branch,Org,... and others.

A191919
  • 3,422
  • 7
  • 49
  • 93
  • The Id is a key (unique) so comparing the key should be sufficient, unless you are looking to compare contents. Can't tell from your question. – jdweng Oct 22 '16 at 21:40
  • @jdweng, for example Id from database it's random number. Id from internet service in my case is null. I cannot compare them. – A191919 Oct 22 '16 at 21:42
  • If the Id is just a unique identifier which I suppose and you want to compare the actual data you have to provide all properties that you´re using in `Equals` in G`GetHashCode`. – MakePeaceGreatAgain Oct 22 '16 at 21:42
  • @HimBromBeere, can you post example of GetHashCode implementation for Gu45 class? – A191919 Oct 22 '16 at 21:51
  • I'm not sure how you can get an exact match. Or are you trying to get the 'best match'? It like comparing an apple and an orange and trying to get an exact match. Yes they are both round and are fruits, but they will never match, – jdweng Oct 23 '16 at 00:14

0 Answers0