0

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 ?

1
  • pls show your tried code Commented Oct 18, 2012 at 5:45

2 Answers 2

6

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);
Sign up to request clarification or add additional context in comments.

Comments

0
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.