I ran into the same problem. .NET seems to believe that the elements in one list are different from the same elements in another list (although they are actually the same). This is what I did to fix this:
Let your class inherit IEqualityComparer<T>, for example.
public class ItemsDTO: IEqualityComparer<ItemsDTO>
{
public bool Equals(ItemsDTO x, ItemsDTO y)
{
if (x == null || y == null) return false;
return ReferenceEquals(x, y) || (x.Id == y.Id);
}
public int GetHashCode(ItemsDTO obj)
{
return this.Id.GetHashCode();
}
}
source
share