Below is the code snippet which shows how group by query is written using LINQ. You can see we have created first a temp variable i.e. ‘GroupTemp’ and then we have used the ‘Select’ clause to return the same.
var GroupCustomers = from ObjCust in objCustomer
group ObjCust by ObjCust.City into GroupTemp
select new {GroupTemp.Key,GroupTemp};
Below image shows group by in action.

Asked In: Many Interviews |
Alert Moderator