I have a L2E query that returns some data that contains duplicate objects. I need to remove those duplicate objects. Basically I should assume that if their IDs are the same
An EqualityComparer
is not the way to go - it can only filter your result set in memory eg:
var objects = yourResults.ToEnumerable().Distinct(yourEqualityComparer);
You can use the GroupBy
method to group by IDs and the First
method to let your database only retrieve a unique entry per ID eg:
var objects = yourResults.GroupBy(o => o.Id).Select(g => g.First());