I used this:
return myListOfContacts.DistinctBy(e => e.Id).Where(e => e.CompanyId == companyId).ToList();
Returns a separate list as requested. The problem is that when the records are duplicated, the returned record is the first in the list.
For example, if in my contacts I have:
[Id - ContactId - Name - FlagIWantThisOne]
1 - 99 - John - true
2 - 56 - Mike - false
2 - 56 - Mike - true
3 - 13 - Dave - false
It returns 3 records:
John, Mike and Dave.
But the record "Mike" I want is a flag with the flag as true.
In general, if the entry is repeated, the list should return the one with the flag set to true, and ignore the rest.
I got distinctBythere, but it returns the first one that it finds in the list.
source
share