如何显示所有员工除了使用Linq之外?

时间:2014-03-25 10:11:00

标签: asp.net-mvc linq entity-framework

IEnumerable<ViewEmployees> us = from u in db.Users
                          join s in db.Designations
                          on new { id = u.DesignationID } equals new { id = s.DesignationID }

                          select new ViewEmployees
                          {
                           EmployeeName = u.Name,
                           EmployeeID = u.Id,
                           EmployeeCode = u.UserName,
                           Designation = u.DesignationID,
                           DesignationName = s.DesignationName,
                          };

它显示所有记录,但我想查看除1 ..当前用户ID

之外的所有记录

2 个答案:

答案 0 :(得分:0)

使用linq中的where子句来过滤/列表

答案 1 :(得分:0)

IEnumerable<ViewEmployees> us = from u in db.Users
                          join s in db.Designations
                          on new { id = u.DesignationID } equals new { id = 
                          s.DesignationID }
                          Where u.Id != LoggedInUserId
                          select new ViewEmployees
                          {
                           EmployeeName = u.Name,
                           EmployeeID = u.Id,
                           EmployeeCode = u.UserName,
                           Designation = u.DesignationID,
                           DesignationName = s.DesignationName,
                          };