asdfghjkjhgfdsa asdfghjkjhgfdsa - 1 year ago 140
SQL Question

SQL to Entity Framework Count Group-By

I need to translate this

statement to a

SELECT name, count(name) FROM people
GROUP by name

Answer Source

Query syntax

var query = from p in context.People
            group p by into g
            select new
              name = g.Key,
              count = g.Count()

Method syntax

var query = context.People
                   .GroupBy(p =>
                   .Select(g => new { name = g.Key, count = g.Count() });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download