How can we do a group by using LINQ query

 Posted by ArticlesMaint on 9/29/2009 | Category: LINQ Interview questions | Views: 7284

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 

Comments or Responses

Login to post response