Linq表达式多个左外部联接错误



我无法执行下面的linq。

   var items(  from p in Patients 
    join q in MURWorksheets on p.PatientId equals q.PatientId into step1
    from s in step1.DefaultIfEmpty()
    join t in MURWorksheetAnswers on s.MURWorksheetId equals t.MURWorksheetId into step2

    from s2 in step2.DefaultIfEmpty()
    select new {p.FirstName , Date = (s.MURDate == null ? DateTime.Now.Date : s.MURDate),
    s2.MURQuestionnaireId,s2.MURExpctedAnswersId}).ToList();

以下是相同的sql供您参考。

select a.FirstName,b.MURDate,c.MURQuestionnaireId,c.MURWorksheetAnswersID from Patients as a
left join MURWorksheet as b on a.PatientId = b.PatientId
left join MURWorksheetAnswers as c on b.MURWorksheetId = c.MURWorksheetId

粘贴的代码中缺少一个等号:

var items = (from p in Patients 
    join q in MURWorksheets on p.PatientId equals q.PatientId into step1
    from s in step1.DefaultIfEmpty()
    join t in MURWorksheetAnswers on s.MURWorksheetId equals t.MURWorksheetId into step2

    from s2 in step2.DefaultIfEmpty()
    select new {p.FirstName , Date = (s.MURDate == null ? DateTime.Now.Date : s.MURDate),
    s2.MURQuestionnaireId,s2.MURExpctedAnswersId}).ToList();

相关内容

  • 没有找到相关文章

最新更新