在实体框架中使用linq的独特记录

时间:2013-06-05 06:22:59

标签: c# linq distinct

根据这个查询,我得到所有具有相同id的记录,但我只想记录一次

var query = (from c in CompObj.EmpInfoes
                     join d in CompObj.Leaves on c.EmpID equals d.ProjectManagerID
                     where c.RoleID == 4 || c.RoleID == 2
                     select new { c.EmpName, c.EmpID });

2 个答案:

答案 0 :(得分:4)

var query = (from c in CompObj.EmpInfoes
             join d in CompObj.Leaves on c.EmpID equals d.ProjectManagerID
             where c.RoleID == 4 || c.RoleID == 2
             select new { c.EmpName, c.EmpID })
    .Distinct();

或者你需要更多东西吗?

答案 1 :(得分:2)

最后添加.Distinct()。