我正在尝试从 LINQ 查询中检索它:
Question 1 - Answer 1
- Answer 2 (Selected)
- Answer 3
Question 2 - Answer 1
- Answer 2
- Answer 3 (Selected)
etc..
我的表如下所示:
Question (with attached multilang support which I'll leave out for now)
QuestionAnswer
Answer (also with multilang)
Response (where the user's response is kept (aka which answer he took -> a specif QuestionAnswer row)
Questionnaire (where all the questionanswers for a single questionnaire are kept)
我尝试了以下方法,但是我得到一个异常,说 .ToList() 在我运行它时不能被翻译成存储过程(所以在执行时,而不是在编译时)(注意这是翻译的):
(from culture in DbContext.Culture
from questionanswer in DbContext.QuestionAnswer
join questionnaire in DbContext.Questionnaire on questionanswer .QuestionnaireID equals questionnaire.QuestionnaireID
where culture.TwoLetterISO.Equals(cultureCode) &&
questionnaire.QuestionnaireID == id
select new QuestionnaireSectionInformation()
{
// Additional data is retrieved here, but thats not important for this question
Questions =
((from question in DbContext.Question
join qmultilang in DbContext.QuestionMultiLang on question.ID equals qMultiLang.Id
join response in DbContext.Response on questionanswer.ID equals response.questionanswerId into possibleReponse
where question.ID == questionanswer.QuestionID &&
qMultiLang.CultureId == culture.ID
select new Topic()
{
Question = qMultiLang.Vraag,
Opmerking = possibleResponse.Any() ? possibleResponse.FirstOrDefault().Commentaar : null,
Answers=
((from answer in DbContext.Answer
join aMultiLang in DbContext.AnswerMultiLang on answer.ID equals aMultiLang.Id
where aMultiLang.CultureId == culture.ID
select new Answer()
{
Answer= aMultiLang.Answer,
Selected = possibleAnswer.Any()
}).ToList())
}).ToList())
}).ToList();
我正在尝试学习更多 LINQ,这就是为什么我不把它分开(通过检索数据并从中提取问题和答案)。
所以问题是:我收到一个异常,说 .ToList() 在我运行时无法转换为存储过程。如果我不能在它们上调用 .ToList() ,如何获取问题的所有子元素?