Thursday, March 7, 2013

GroupBy Multiple Columns in LINQ

How do you  GroupBy Multiple Columns in LINQ? 

The solultion is pretty simple:
Given a collection of Books where each book has an Author and a Name, if you have group group by all authors then by the name of the book, you can do


Books.GroupBy(book => new { book.Author, book.Name });