答案 0 :(得分:1)
试试这个: SQL就像语法一样。
from a in Assignments
group a by a.Id into gr select gr.FirstOrDefault()
Lambda表达式:
Assignments
.GroupBy (a => a.Id)
.Select (gr => gr.FirstOrDefault ())
答案 1 :(得分:0)
试试这个,它的作品。我希望这就是你所需要的。
var query01 = context.FirstTable
.GroupBy(p => p.ID
,(ky, el) => new { ky.Value , FirstCountry = el.Select(p => Country).Take(1)});
var Result = query01
.Join(context.FirstTable
, ul => new
{
Id = ul.Value
,Country = ul.FirstCountry.FirstOrDefault()
}
, fl => new
{
Id = (int)fl.ID
, Country = fl.Country
}
, (ul, fl) => new { fl }).ToList();