Linq where子句不过滤

时间:2015-02-10 17:00:06

标签: c# asp.net linq lambda 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);
            }
        }

2 个答案:

答案 0 :(得分:1)

您确定您拥有IT或HR的男性员工吗?

如果你这样做,你确定性别列的M大写吗?

尝试删除区分大小写:

var empInDept = dept.Employees.Where(x => x.Gender.ToLower().Trim() == "male");

答案 1 :(得分:0)

您可以在<{1}}表达式中放置一个断点来逐步执行它。