Linq中的not in的使用方法

时间:2024-01-22 08:20:52
T:sql语句

select * from DB_FacultyReserveDetails details
join DB_FacultyreserveRule rul on details.[FK_ FacultyReserveRule] =rul.Id
where details.FK_BedInfo not in (select FK_BedInfo from SD_StuLiveInfo)


Linq语句:

var query = (from res in db.DB_FacultyReserveDetails
join faculty in db.DB_FacultyreserveRule on res.FK__FacultyReserveRule equals faculty.Id into facu
from selfiquery in facu.DefaultIfEmpty()
where !(from ii in db.SD_StuLiveInfo
select ii.FK_BedInfo).Contains(res.FK_BedInfo)
&& selfiquery.BeginDate <= System.DateTime.Now
&& selfiquery.EndDate >= System.DateTime.Now
join view in db.View_FullDept on res.Fk_DeptClass ?? res.Fk_DeptInfoMajor ?? res.Fk_DeptInfoFaculty equals view.ID
group view by new { code = view.ID, name = view.fullName } into g
select new 
{
Code = g.Key.code,
Name = g.Key.name,
Value = "0"
}).ToList();