I have three models: Quiz, Question, and Answer.
public class Quiz
{
public int ID { get; set; }
public string Title { get; set; }
public ICollection<Question>? Questions { get; set; }
}
public class Question
{
public int ID { get; set; }
public string Title { get; set; }
public int QuizID { get; set; }
public Quiz? Quiz { get; set; }
public ICollection<Answer>? Answers { get; set; }
}
public class Answer
{
public int ID { get; set; }
public string Label { get; set; }
public bool IsCorrect { get; set; }
public int QuestionID { get; set; }
public Question? Question { get; set; }
}
In my Pages\Quizzes\Details.cshtml.cs
, I am getting a Quiz model by ID and also grabbing all of it's related questions like this:
var quiz = await _context.Quizzes
.Include(quiz => quiz.Questions)
.FirstOrDefaultAsync(m => m.ID == id);
Which works great, but when I inspect the Questions
List, the Answers
list is null. Is there a way I can modify the _context.Quizzes.Include...
statement to also grab all Answer
models for the Question
for that specific Quiz ID?