我希望得到的结果显示了拥有最多年经验的人的名字。结果如下:
如何使用Max()
代替YearsOfExperience == 4
修改我的代码以获得该结果?
from es in EmployeeSkills
where es.YearsOfExperience == 4
select new
{
Name = Employees
.Where(emp => emp.EmployeeID == es.SkillID)
.Select(emp => new
{
Name = emp.FirstName + " " + emp.LastName
})
}
答案 0 :(得分:0)
请尝试使用FirstOrDefault:
MERGE_NAME
ABC,XYZ
答案 1 :(得分:0)
这可行...在LinqPad中尝试这个
<div class="box">
<input id="qty" value="0" />
<button id="up" onclick="modify_qty(1)">LIKE</button>
</div>
答案 2 :(得分:0)
有几种不同的方法可以做到这一点。这是少数几个之一:
int maxYears = (from s in EmployeeSkills
select s.YearsOfExperience).Max();
var query = (from s in EmployeeSkills
where s.YearsOfExperience == maxYears
select s).SingleOrDefault();
另一种方式:
var query = EmployeeSkills
.SingleOrDefault(e => e.YearsOfExperience
.Equals(EmployeeSkills.Max(y => y.YearsOfExperience)));