I have 2 tables. MarkQuestion and Question.
MarkQuestion has:
IDQuestion,
IDUser,
Mark
Question has:
IDQuestion,
Text
I want to extract text of each question and average mark for each question:
I tried something like this:
var questions = from mark in Entities.MarkedQuestions
join question in Entities.Questions on mark.IDQuestion equals question.IDQuestion
group mark by mark.IDQuestion into markGroup,
question by question.IDQuestion into questionGroup
select new ModelView.MarkQuestionModel
{
AverageMark = markGroup.Average(x => x.Mark),
Text = ..
};
How to solve this?
It sounds to me like you want a group join, so that you have two range variables – one representing a question, and another representing all the marked questions for that particular question.
Here’s the query expression syntax you’d use:
For dot notation, you’d use the
GroupJoinmethod to achieve the same result.