C# 对LINQ的SQL查询(使用带两个键的join)
我已经得到了SQL查询并尝试使用LINQ,因为如果EF。有人能看一下吗?请告诉我我的错在哪里?SQL查询正在工作,但LINQ不返回任何数据。基本上有两个表A和表B。我想连接A\B,即(使数据存在于表A中,但不存在于表B中) 我试过了,但没用。当我连接两个表时,需要两个键值相匹配,正如您从SQL表中看到的C# 对LINQ的SQL查询(使用带两个键的join),c#,sql,linq,C#,Sql,Linq,我已经得到了SQL查询并尝试使用LINQ,因为如果EF。有人能看一下吗?请告诉我我的错在哪里?SQL查询正在工作,但LINQ不返回任何数据。基本上有两个表A和表B。我想连接A\B,即(使数据存在于表A中,但不存在于表B中) 我试过了,但没用。当我连接两个表时,需要两个键值相匹配,正如您从SQL表中看到的 var ReqList = from course in employeeCourseRepository.EmployeeCourseList join train
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 };
原始查询为左连接,而代码为内部查询,请将其更改为:
var ReqList = from course in employeeCourseRepository.EmployeeCourseList.Where(c => c.CourseID == Blist.CourseID)
join training in employeeTrainingRepository.EmployeeTrainingList
on new { c = course.CourseID, e = course.EmployeeID } equals new { c = training.CourseID, e = training.EmployeeID } into j
from res in j.DefaultIfEmpty()
select new { empID = course.EmployeeID };
尝试在连接中只放置一个键,修改的对象是两个项目((course.CourseID==Blist.CourseID)&&(course.CourseID==training.CourseID))@AdilSari很乐意提供帮助!
var ReqList = from course in employeeCourseRepository.EmployeeCourseList.Where(c => c.CourseID == Blist.CourseID)
join training in employeeTrainingRepository.EmployeeTrainingList
on new { c = course.CourseID, e = course.EmployeeID } equals new { c = training.CourseID, e = training.EmployeeID } into j
from res in j.DefaultIfEmpty()
select new { empID = course.EmployeeID };