1
我加入LINQ表達式是像follwowing左外連接後,內部聯接LINQ C#
var kycKist = (from aloc in this._classesDataContext.tblUsers
join sup in this._classesDataContext.BR_Supervisors on aloc.SupId equals sup.Id
where
(aloc.UserTypesId == 1 &&
((aloc.CreatedOn <= attendanceDate && aloc.ModifyOn >= attendanceDate &&
aloc.Active == false) ||
(aloc.Active == true && aloc.CreatedOn <= attendanceDate &&
aloc.ModifyOn <= attendanceDate)))
select
new
{
sup.Name,
sup.Region,
sup.Area,
sup.Distribution_Name,
sup.BR_Alloc,
sup.Active
}).ToList();
現在我想使外與上面的代碼
left outer join atn in this._classesDataContext.BR_Attendence on sup.ID equals atn.SupId where atn.date =attendanceDate
我的代碼草案將加入看起來像這樣
var kycKist = (from aloc in this._classesDataContext.tblUsers
join sup in this._classesDataContext.BR_Supervisors on aloc.SupId equals sup.Id
left outer join atn in this._classesDataContext.BR_Attendence on sup.ID equals atn.SupId where atn.date =attendanceDate
where
(aloc.UserTypesId == 1 &&
((aloc.CreatedOn <= attendanceDate && aloc.ModifyOn >= attendanceDate &&
aloc.Active == false) ||
(aloc.Active == true && aloc.CreatedOn <= attendanceDate &&
aloc.ModifyOn <= attendanceDate)))
select
new
{
Present=(atn!=null)?atn.PresentBR:0,
sup.Name,
sup.Region,
sup.Area,
sup.Distribution_Name,
sup.BR_Alloc,
sup.Active
}).ToList();
如何實現上面的左外連接?
所以我想問題是「我如何做一個與LINQ左加入」? – usr