var qry = from _Cr in _er.Courses
from _R in _er.ResultsHeaders
where _R.Studentid == studentid
&& !_Cr.CourseID.Contains( _R.CourseID )
select new Obj_getCourses
{
Courseid = _Cr.CourseID,
CourseName = _Cr.CourseName
};
_er.CoursesTable中有4个值,_er.ResultsHeader表为空。我期待查询中的4个值,但查询没有返回任何值。这是我试图在LINQ中编写的查询。
Select * \
from Courses \
where courseid not in (Select courseid from ResultsHeader where studentid = 123);
帮助要求。
提前致谢
答案 0 :(得分:0)
要获取您发布的SQL,您应该尝试以下查询:
var qry = from _Cr in _er.Courses
where !_er.ResultsHeader.Where(r => r.StudentId == studentId)
.Select(r => r.CourseID)
.Contains(_Cr.CourseID)
select new Obj_getCourses
{
Courseid = _Cr.CourseID,
CourseName = _Cr.CourseName
};
答案 1 :(得分:0)
这可以为您提供所需的结果。我用C#语句风格编写它,所以希望它具有LINQ风格并不是先决条件......
var qry = _er.Courses
.Where( c => !c.CourseID.Contains(_er.ResultsHeader
.Where( r => r.StudentID == 123)
.Select(r => r.CourseID)
)
.Select(c => new Obj_getCourses
{
Courseid = c.CourseID,
Coursename = c.CourseName
});