Avatar of JedNebula
JedNebula
Flag 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.

Regards,

Rawden.
.NET ProgrammingVisual Basic.NETLINQ Query

Avatar of undefined
Last Comment
JedNebula

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ioannis Paraskevopoulos

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
JedNebula

ASKER
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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy