Linq 中join实现多条件左连接
例子如下:
public dynamic GetPersonByDirector(string directorCode,int assessCycle) { var query = from person in container.T_BASE_PERSON join plan in container.T_PLAN_PLAN on new {PERSON_ID = person.ID, ASSESS_CYCLE = (int?) assessCycle} equals new {plan.PERSON_ID, plan.ASSESS_CYCLE} into temp from personPlan in temp.DefaultIfEmpty() join assessinfo in container.T_BASE_ASSESSINFO on person.ID equals assessinfo.PERSON_ID join org in container.T_BASE_ORG on assessinfo.DEPT_ORG_CODE equals org.ORG_CODE where assessinfo.DIRECTORS_ID.Contains(directorCode) && assessinfo.ASSESS_CYCLE == assessCycle select new { PERSON_CODE = person.PERSON_CODE, PERSON_NAME = person.PERSON_NAME, ORG_NAME = org.ORG_NAME, STATUS = personPlan == null ? -1 : personPlan.STATUS, //左连接,可能为空,下同 ID = person.ID, PLAN_ID = personPlan == null ? 0 : personPlan.ID }; return query.AsQueryable(); }
如代码中红色标红所示。