I’ve got a DataTable where i want to perform a GroupBy query on.
year url type id
=============================
someurl image 0
2003 date 0
someurl image 1
2009 date 1
I’ve managed to group on my id, but I am not able to select the columns “year” and “Url”.
This is my query:
var query = from row in table.AsEnumerable()
let uri = row["uri"]
group row by row.Field<int>("id") into grp
orderby grp.Key
select new
{
ID = grp.Key,
};
How can i select the columns year and url?
Thanks in advance.
When you group by in LINQ your group (grp) in your case is an enumerable containing all the entries in a group (data rows in your case). You can then either foreach the entries or use aggregate functions like Max, First, etc. to extract a single value from the enumerable