Group By Using LINQ

Vishalbedre
Posted by Vishalbedre under LINQ category on | Points: 40 | Views : 1317
Here is the code snippet of Group By using LINQ. IN this we have taken the tables from Northwind database and joined them.
 var data = from c in db.Customers
join o in db.Orders
on c.CustomerID equals o.CustomerID
select new
{
CustomerName = c.ContactName,
ORderId = o.OrderID
};

var d = from dd in data
group dd by dd.CustomerName into g
select new
{
cNAme = g.Key,
rCount = g.Count()
};

For more LINQ related methods visit http://www.dotnetfunda.com/articles/article993-frequently-used-linq-extension-methods.aspx
Thanks

Comments or Responses

Login to post response