This tip describes how we can use grouping in LINQ.
As we know Group keyword allows as to group returned results into separate lists. When we use the Group keyword, IT return a list of lists. I want to group BodyType column and then count.
In T-SQl we write as follows
SELECT BodyType, COUNT(*) AS BodyTypeCount FROM Inventory GROUP BY BodyType
The same thing in LINQ query using C# Look like.
var BodyTypeGroups = from row in dcDC.Inventories.AsEnumerable()
group row by row.BodyType into rowGroup select new
VehicleBodyType = rowGroup.Key,
BodyTypeCount = rowGroup.Count()
In another way
IEnumerable<IGrouping<string, Inventory>> BodyTypeGroups = from row in
group row by row.BodyType;
foreach (IGrouping<string, myDateTable> BodyTypeGroup in productGroups)
For more information on IGrouping Interface, please visit the below link: