PamZy
PamZy

Reputation: 123

Distinct() not working

I am trying to fetch a list of distinct values from a collection. But I am unable to do so.

For example:

var someValue = (Data.Cast<IDetailType>().Select(x => x.Common.Provider)
                                         .Union(Data.Cast<NDetailType>().Select(x => x.Common.Provider))).Distinct();

This query returns me all sets of Data, along with repetition data also.

Upvotes: 0

Views: 149

Answers (1)

TalentTuner
TalentTuner

Reputation: 17556

You need to tell Distinct , how to compare the objects , please see the overload Distinct(IEqualityComparer<T>)

and see the post how to do it

Upvotes: 1

Related Questions