Reputation: 11721
I have a datatable dt which has supplierId and SubsystemId as 2 of its columns . I want to find if there is any duplicate entries for the combination of these two column values .
I am a starter to Linq . How can I do this ?
Upvotes: 0
Views: 6062
Reputation: 11721
var dups = from row in dt.Copy().AsEnumerable()
group row by new { SubsystemTypeId = row.Field<int>("SubsystemTypeId"), SupplierId = row.Field<int>("SupplierId") }
into grp
where grp.Count() > 1
select grp.Key;
Thanks SriRam
Upvotes: 0
Reputation: 1888
You can find your duplicates by grouping your elements by supplierId and SubsystemId. Do a count on them afterwards and you will find which ones are duplicates.
This is how you would isolate the dupes :
var duplicates = items.GroupBy(i => new {i.supplierId, i.SubsystemId})
.Where(g => g.Count() > 1)
.Select(g => g.Key);
Upvotes: 6