我有一张看起来像这样的表:
最喜欢的颜色|最喜欢的食物|最喜欢的舞蹈|日期
现在我想按喜欢的颜色和喜欢的食物分组。然后按日期(最新)排序的每组中排名前3位。我似乎无法使用LINQ使其工作。
答案 0 :(得分:8)
像这样:
from x in thingy
group x by new { x.Color, x.Food } into g
select new {
g.Key.Color,
g.Key.Food,
Items = g.OrderByDescending(x => x.Date).Take(3)
}