I'm trying to retrieve this from a LINQ-query:
Question 1 - Answer 1
- Answer 2 (Selected)
- Answer 3
Question 2 - Answer 1
- Answer 2
- Answer 3 (Selected)
etc..
My tables look like this:
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)
I've tried the following, but I get an exception saying that .ToList() can't be translated into a stored proc when I run it (so at Excecution time, not at compile time) (note this is translated):
(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();
I'm trying to learn some more LINQ, that's why I'm not pulling this apart (by just retrieving the data and extracting the questions and answers out of it).
so the problem is: I get an exception saying that .ToList() can't be translated into a stored proc when I run it. How can I get all the child elements of the questions if I can't call .ToList() on them?