How to use GroupBy in LINQ?

It is used for grouping of elements based on a specified value. Each group has a key. It returns a collection of IGrouping<Key, Values>.

DataContext context = new DataContext();
var query = from ord in context.tblOrder group ord by ord.CustomerID into grouping select new {
	grouping.Key, grouping
};

 

Tagged , . Bookmark the permalink.

Leave a Reply