在查询中经常用到分组查询,例如根据顾客的国家分组,查询顾客数,一般写法是
var q = from g in
(from c in db.Customers
group c by c.Country)
select new { g.Key, Count = g.Count() };
为了简化此语法,可以使用into关键字,来简化嵌套查询。
var q =from c in db.Customers
group c by c.Country into g
select new { g.Key, Count = g.Count() };