My question is identical to two previously asked questions
LINQ TO DataSet: Multiple group by on a data table, the only difference with this question is that I need to do that with Method Syntax.
and
LINQ Group By Multiple fields -Syntax help - the difference with this question is that I need to do this using LINQ-to-DataSet.
I'm trying to group the Customers by Country, with the result (expected) as below:
COUNTRYCODE CUSTOMERNAME
USA Microsoft
USA IBM
CAN RIM
CAN Tim Horton
GER BMW
How do we do this? Thank you.
EDIT:
Here's the messy code I'm struggling with.
var query = orders.AsEnumerable()
.GroupBy(t => new {CountryCode= t.Field<string>("CountryCode"),
CustomerName = t.Field<string>("CustomerName"),
(key, group)=> new {Key1 = key.CountryCode, Key2=key.CustomerName})
.Select(t => new {t.Key1, t.Key2});
The code in my EDIT worked: