任何人都可以知道爲什麼這個代碼將正常運行:LINQ的where子句不過濾
EmployeeContextDataContext empContext = new EmployeeContextDataContext();
var departaments = empContext.Departments.Where(x => x.Name == "IT" || x.Name=="HR");
foreach (Department dept in departaments)
{
Response.Write(dept.Name);
var empInDept = dept.Employees;
foreach (var employee in empInDept)
{
Response.Write(employee.FirstName + employee.Gender);
}
}
我添加。凡時刻(X => x.Gender == 「男」);它不會拋出任何東西在屏幕上?
foreach (Department dept in departaments)
{
Response.Write(dept.Name);
var empInDept = dept.Employees.Where(x => x.Gender =="Male");
foreach (var employee in empInDept)
{
Response.Write(employee.FirstName);
}
}
因爲你沒有任何男性員工...... – 2015-02-10 17:01:21
性別是一串嗎?在過濾之前,您是否看過'員工'以確保其中一些實際上具有該價值? – 2015-02-10 17:02:04
@JustinPihony只是不在IT或人力資源部。 :) – 2015-02-10 17:02:42