group by and count with linq vb.net

26,063

Solution 1

Not sure what your table looks like, but give this a try. Also I'm sure there are plenty of answers on stack that illustrate grouping in VB. This might be a duplicate question.

Dim artnrGroups = From a In table _
                    Group a By Key = a.artnr Into Group _
                    Where Group.Count() > 1
                    Select artnr = Key, numbersCount = Group.Count()

Solution 2

And you can put the Count() into that query like this

Dim duplicateRows = From row In table _
           Group row By row.artnr Into g _
           Where g.Count() > 1 _
           Select row
Share:
26,063
derstauner
Author by

derstauner

Updated on July 09, 2022

Comments

  • derstauner
    derstauner almost 2 years

    I have a datatable. I would like to list the double entries. This would I make with a simple sql query like this:

    SELECT artnr, COUNT(artnr) AS cnt FROM table GROUP BY artnr HAVING COUNT(artnr)>1
    

    How should this looke with linq?

    Every time, when I need to work with linq, I get always stuck with it. I dislike it really.

    Thanks.