Nate Pet
Nate Pet

Reputation: 46222

LINQ - Group by lambda expression

Say I have the following:

var OrderCounts = from o in Orders
                  group o by o.CustomerID into g
                  select new {
                         CustomerID = g.Key,
                         TotalOrders = g.Count()
                  };

How can this be converted to a Lambda expression

Upvotes: 1

Views: 13942

Answers (1)

Nathan Taylor
Nathan Taylor

Reputation: 24606

var OrderCounts = customers
        .GroupBy (o => o.CustomerID)
        .Select (o => new { CustomerID = o.Key, TotalOrders = o.Count () })

Upvotes: 9

Related Questions