在尝试将所有记录分组然后求和后,我尝试以最大值返回记录。我能够得到总和,但不能返回最大值的完整记录。
这是我到目前为止所获得的最大总和值?
from es in EmployeeSkills
group es by es.Employee.FirstName + " " + es.Employee.LastName into empGroup
select new
{
Name = empGroup.Key,
YOE = (from y in empGroup select y.YearsOfExperience).Sum ()
}
答案 0 :(得分:1)
您可以使用Aggregate
扩展方法
var query=from es in EmployeeSkills
group es by es.Employee.FirstName + " " + es.Employee.LastName into empGroup
select new
{
Name = empGroup.Key,
YOE = empGroup.Select(y=>y.YearsOfExperience).Sum()
};
var result=query.Aggregate((seed, current)=>current.YOE>seed.YOE?current:seed);
或者您也可以使用MoreLinq库中的MaxBy
扩展方法:
var result=query.MaxBy(e=>e.YOE);