使用下面的代码,我将获得员工的所有姓名。
如何添加where子句以仅将empStatus = 1的当前雇员获取?
private void BindDropDownList()
{
var employees = dbEmployee.employeestable.Select(x => new
{
FullName = x.emp_first + " " + x.emp_last,
Id = x.empid
}).ToList();
ViewBag.Employees = new SelectList(employees, "FullName", "FullName");
}
答案 0 :(得分:1)
在Where
之前添加Select
过滤器
var employees = dbEmployee.employeestable
.Where(x => x.empStatus == 1) //<----HERE
.Select(x => new {
FullName = x.emp_first + " " + x.emp_last,
Id = x.empid
})
.ToList();
//...