1、单张表:
var q =
from p in db.Products
group p by p.CategoryID into g
select g;
2、多表多字段参与分组:
from a in TableA
join b in TableB on a.Id equals b.aId
where ((b.Type == 1 || b.Type == 2 || b.Type == 5) && b.State == 1)
group new { a.Id, b.Name,b,CreateDate } by new { a.Id, b.Name } into g
select (new MyClass { Id = g.Key.Id, Name = g.Key.Name ?? "" });
class MyClass
{
public int Id { get; set; }
publid string Name { get; set; }
}