Linq表达式多个左外连接错误
Posted
技术标签:
【中文标题】Linq表达式多个左外连接错误【英文标题】:Linq expression multiple left outer join error 【发布时间】:2013-08-21 14:59:32 【问题描述】:我无法执行以下 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
【问题讨论】:
有错误提示吗? 是的,使用 LinqPad; expected Invalid expression term 'in'
那里是否有两个错误“;预期”和“无效的表达式术语'in'”?您可以编辑问题并在课堂上包含代码吗?
我假设您的代码是“var items = ...”而不是“var items(...”?
感谢 GrandMasterFlush,如果您在答案中发帖,您可能会获得积分。非常感谢,你回答 camse 1st
【参考方案1】:
您在粘贴的代码中缺少等号:
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();
【讨论】:
以上是关于Linq表达式多个左外连接错误的主要内容,如果未能解决你的问题,请参考以下文章