Linq

Group by with Where clause in Linq c#

Group by with Where clause in Linq c#, someone asked me to explain?

This following example Query will clear how to filter records using where clause and group by from a set of records.

Many of us are facing problem with grouping elements this example provides best practices for one who wants to know group different types of data.

var result = from queryResult in db.Orders.AsEnumerable() where queryResult.ShipCountry == "UK"
                                group queryResult by queryResult.ShipCity into rowGroup
                                select new
                                {
                                    Name =rowGroup.Key,
                                    OrdersCount= rowGroup.Count()                                };

Post your comments / questions