我有一个与特别问题ID相关的不同答案。我必须对每个问题的答案进行分组。
Question Table ---------- QuestionID QuizID QuestionText IsMultipleAnswers Answer Table -------- AnswerID QuestionID AnswerText IsCorrectAnswer
var query = from qst in context.Questions
join ans in context.Answers
on qst.QuestionID equals ans.QuestionID
扩展查询以将与每个questionID相关联的答案分组的方法是什么?
答案 0 :(得分:3)
答案 1 :(得分:2)
只需使用group by运算符:
var query = from qst in context.Questions
join ans in context.Answers
on qst.QuestionID equals ans.QuestionID
group ans by ans.QuestionID into groups
select groups;