c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
Linq

Group by with Where clause in Linq c#

| | Linq

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()
                               };