I came up with the scenario that i m getting multiple question and there option MCQ's using single id i want to show random question on Partial view and when user click next button it should load another random question using MVC EF. Here is my code.
var modeldata =
Db.ExamQuestions.Include("ListofOptions").Where(x => x.FkExamId == model.ExamId).Select(q => new QuestionViewModel
{
QuestionId = q.ID,
QuestionDescription = q.QuestionDescription,
ExamId = q.FkExamId,
CorrectOption = q.CorrectOption,
ListofOption = q.ListofOptions.Select(o => new QuestionOptionViewModel
{
OptionA = o.OptionA,
OptionB = o.OptionB,
OptionC = o.OptionC,
OptionD = o.OptionD
}).ToList()
}).OrderBy(q => q.QuestionId).Take(1).ToList();