Link to home
Start Free TrialLog in
Avatar of JedNebula
JedNebulaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Linq Syntax - Find Duplicates

I am writing a class in a VB.NET project which will compare data between two data sources.

I have two datatables (tblSource and tblDest)

I am looking for a generic 'Find Duplicates' Linq statement where I DO NOT KNOW the Key Columns at design time.

For example, the following will work if I know the table is going to have Columns called CusOrderID and CusOrderStore:

Dim duplicates = tblDest.AsEnumerable().GroupBy(Function(r) New With { _
                            Key .CusOrderID = r.Item("CusOrderID"), _
                            Key .CusOrderStore = r.Item("CusOrderStore") _
                        }).Where(Function(gr) gr.Count() > 1).[Select](Function(g) g.Key)

Open in new window

But seeing at this is a generic class, I will not know these column names.

I would like help with amending the statement above to run off a DataColumn array variable instead. If that is possible.


Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JedNebula


Annoyingly I don't actually have a need for this any longer as the problem has been circumvented.

I haven't had a chance to look properly at the solution, but it does like the sort of thing I need so I'll give you the points. Sorry for the delay.