Background
I have a dataset with lots of repeating values, which have come from a CSV file.
I know how I would group, sort and add a count if the data was in a database using SQL.
SQL
SELECT pass, count(pass)
FROM table
GROUP BY pass
ORDER BY pass, count(pass) ASC
I've attempted to do this using LINQ.
What I've Tried?
//Sort
dtData.DefaultView.Sort = "Pass";
dtData = dtData.DefaultView.ToTable();
//Group
dtData = dtData.AsEnumerable()
.GroupBy(r => new { Col1 = r["Pass"] })
.Select(g => g.OrderBy(r => r["Pass"]).First())
.CopyToDataTable();
However I need a extra column called count, else the group is pointless. How can i get an extra column with a count?
Note: To the person who flagged this question as a duplicate of the below question, please see remark above. The flagged question is just how to sort dataset.