I have a datatable like the following
A | B
-------
1 | b1
1 | b2
1 | b3
2 | b4
2 | b5
3 | b6
3 | b7
3 | b8
3 | b9
How can I write a LINQ command to select the first row on each distinct value on column A:
A | B
---------
1 | b1
2 | b4
3 | b6
You need to group by column A then select the first entry of B. (You may want to sort your B-column values)
There’s a code sample here:
Get distinct records using linq to entity