tags:

views:

62

answers:

2

I have a different answers associated with particulary QuestionID.I have to group the answers of each question.

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 

What is the way to extend my query to group the answers associated with each questionID ?

+2  A: 

The 101 LINQ samples page for GroupBy might help.

Richard Ev
+1  A: 

Just use the group by operator:

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;
Martinho Fernandes