I\'m trying to do a query that does not include repeated IdUser
values, but does not work.
this is my linq query:
var
When comparing class instances (vs. anonymous types) you need to define "equality". For anonymous types the compiler assumes that equality means "all fields are equal" like SQL does. So you have a few choices:
.Distinct()
, and convert to a strong type afterwards,IEqualityComparer
class and pass that to Distinct
,Equals
(and GetHashCode
) in Usuers
2) and 3) will be very similar code. 2) is more flexible (you can define equality in different ways by defining different classes, while 3) will be used whenever you compare Uusers
insatnces (not just in this query).
See my answer to a similar problem here.