这是使用LINQ实现左外部联接的方式。您应该使用GroupJoin(
join...into语法):
from d in context.dc_tpatient_bookingdjoin bookingm in context.dc_tpatient_bookingm on d.bookingid equals bookingm.bookingid into bookingmGroupfrom m in bookingmGroup.DefaultIfEmpty()join patient in dc_tpatient on m.prid equals patient.prid into patientGroupfrom p in patientGroup.DefaultIfEmpty()// ... other joins herewhere d.processid == 6 && ((m.branchId == 1 && d.DestinationBranchID == 0) || (d.DestinationBranchID == 1 && d.sendstatus == "R"))// ... other conditions hereorderby d.priority descending, m.bookingidselect new { d.bookingid, d.labid, d.processid, p.prid, p.prno, m.bookingid // need for grouping} into xgroup x by x.bookingid into gselect g
该查询联接了三个表。您可以以相同的方式加入其余表。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)