我得到了sql查询并尝试使用linq,因为如果ef。有人能看一下吗?请告诉我哪里错了?sql查询正在工作,但linq不返回任何数据。基本上有两个表a和表b。我想加入a\b,这是(使我的数据存在于表a中,但不在表b中)
SqlQueryText = " SELECT A.EmployeeID" +
" FROM EmployeeCourseModels A " +
" LEFT JOIN EmployeeTrainingModels B " +
" ON A.EmployeeID = B.EmployeeID and a.CourseID = B.CourseID" +
" WHERE(B.CourseID is null and B.EmployeeID is null) AND A.CourseID = " + courseID;
我试过了,但没用。当我连接两个表时,我需要两个键值来匹配,正如您从sql表中看到的那样。
var ReqList = from course in employeeCourseRepository.EmployeeCourseList
join training in employeeTrainingRepository.EmployeeTrainingList
on new { c = course.CourseID, e = course.EmployeeID } equals new { c = training.CourseID, e = training.EmployeeID }
where (course.CourseID == Blist.CourseID)
select new { empID = course.EmployeeID };
1条答案
按热度按时间kmpatx3s1#
原始查询是左连接,而代码是内部查询,请将其更改为: