So to fix this you will need to navigate to the DTO that is being used as the type, in this case 'ObjDTO'. You will need to create a custom equality comparer.
I used the following code to make this comparer:
public string Item1 {get;set;}
public int Item2 {get;set;}
public override bool Equals(object obj)
{
var item = obj as ObjDTO;
if (item == null)
{
return false;
}
return this.Item1 == item.Item1 && this.Item2 == item.Item2;
}
public override int GetHashCode()
{
if (this.Item1 == null && this.Item2 == 0)
{
return base.GetHashCode();
}
return this.Item1.GetHashCode() + this.Item2.GetHashCode();
}
So, the reason distinct was not working is because each object in that DTO being accepted had a unique hashcode, this is invisible. So with that in mind, our custom comparer, does the job of comparing the values within the object, then combines the hashcodes and returns.
And that gives us a list of distinct values with unique hashcodes.