If you want to compare the values ββfor your dto objects, you need to override the Equals and GetHashCode methods.
For example, for a class:
public class DTOPersona { public string Name { get; set; } public string Address { get; set; } }
If you think that two objects of the DTOPersona class with the same name (but not an address) are equivalent objects (i.e. the same person), your code might look something like this:
public class DTOPersona { public string Name { get; set; } public string Address { get; set; } protected bool Equals(DTOPersona other) { return string.Equals(Name, other.Name); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } if (obj.GetType() != this.GetType()) { return false; } return Equals((DTOPersona) obj); } public override int GetHashCode() { return (Name != null ? Name.GetHashCode() : 0); } }
source share