Linq Syntax - Find Duplicates

JedNebula
JedNebula used Ask the Experts™
on
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.

Regards,

Rawden.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
I have never used it myself, so forgive me if it is not the right thing for you, but you can check out the Dynamic LINQ Library.

http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx

Author

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial