我如何找到所有留在城市的员工=“波士顿”? Linq查询假设EmployeeData是一个Entity对象,该实体Address可以是一个集合吗?
我尝试了这个并且结果没有返回,但是有关于city =“Boston”的记录:
var result = empQuery.Select(a => a.Address.Where(f => f.city.ToString().ToLower() == "boston"));
答案 0 :(得分:1)
应该做同样的事情:
var queryEmployees = employees.Where(emp => emp.Address.City == "Boston")
var queryEmployees = from emp in employees where emp.Adress.City == "Boston"
select emp;
编辑:由于每个员工都有一个地址集合,您可以这样查询:
var result = from x in employees from y in x.Adress where y.City == "Boston" select x;