日期:2014-05-20  浏览次数:20866 次

Linq左连接+多条件
select p.Id,r.Id,s.Id,s.Name,p.Title,p.TotalScore from JHExamPaper as ep
inner join Paper as p on ep.PaperId=p.Id
inner join Subject as s on p.SubjectId=s.Id
left join ExamPaperStudent as eps on ep.PaperId=eps.PaperId and eps.ExamId='B39A5BEE-8021-4A0D-8CC2-4BDEFC580579' and UserId='110813D3-AF1D-41A2-9F39-B44604CA2BC6'
left join Report as r on eps.Id=r.EPSId

如何把上面的SQL转化成Linq,求大神指教,在线等。

------解决方案--------------------
C# code

var query=from ep in JHExamPaper
          join p in Paper on ep.PaperId equals p.Id
          join s in Subject on p.SubjectId equals s.Id
          join eps in ExamPaperStudent on ep.PaperId equals eps.PaperId into leftJoinGroup
          from eps in leftJoinGrou.DefaultIfEmpty()
          join r in Report on eps.Id equlas r.EPSId into Left
          from r in Left.DefalutIfEmpty()
          where eps.ExamId=="B39A5BEE-8021-4A0D-8CC2-4BDEFC580579" && eps.UserId=="110813D3-AF1D-41A2-9F39-B44604CA2BC6"
          select new 
          {
            p.Id,r.Id,s.Id,s.Name,p.Title,p.TotalScore 
          };