You can simulate with this
Questions List - main list
QuestionsOptions list - secondary list
Respose List - secondary list
for example: join 1 ( question list and question option list ) -> it will give 2 rows
join 1 results joined with Resonse list -> gives 4 rows as the parent(for second join) ( join 1 has 2 rows )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using console_poc;
namespace oops1
{
public class Db
{
public Db()
{
Questions = new List<Question>();
Questions.Add(new Question() { Id = 1, Options = 1, PageNumber = 1, Question1 = "q1", QuestionRanking = 1, QuestionTypeId = 1 });
QuestionOptions = new List<QuestionOption>();
QuestionOptions.Add(new QuestionOption() { QuestionId = 1, QuestionOptionRanking = 1 });
QuestionOptions.Add(new QuestionOption() { QuestionId = 1, QuestionOptionRanking = 2 });
QuestionOptions.Add(new QuestionOption() { QuestionId = 2, QuestionOptionRanking = 3 });
QuestionOptions.Add(new QuestionOption() { QuestionId = 2, QuestionOptionRanking = 4 });
Responses = new List<Response>();
Responses.Add(new Response() { Answer = "a1", QuestionId = 1 });
}
public List<QuestionOption> QuestionOptions { get; set; }
public List<Question> Questions { get; set; }
public List<Response> Responses { get; set; }
}
class Program
{
static void Main(string[] args)
{
int page = 1;
Db db = new Db();
var question = (from q in db.Questions
join qo in db.QuestionOptions on q.Id equals qo.QuestionId
join r in db.Responses on q.Id equals r.QuestionId
where q.PageNumber == page
select new GetQuestionViewModel
{
QuestionOptionRanking = qo.QuestionOptionRanking,
Id = q.Id,
Options = q.Options,
QuestionTypeId = q.QuestionTypeId,
Question1 = q.Question1,
QuestionRanking = q.QuestionRanking,
Answer = r.Answer
}).ToList();
}
}
}
public class Question
{
public int Id { get; set; }
public int PageNumber { get; set; }
public Nullable<int> Options { get; set; }
public string Question1 { get; set; }
public int QuestionTypeId { get; set; }
public Nullable<int> QuestionRanking { get; set; }
}
public class QuestionOption
{
public int QuestionId { get; set; }
public Nullable<int> QuestionOptionRanking { get; set; }
}
public class Response
{
public int QuestionId { get; set; }
public string Answer { get; set; }
}
public class GetQuestionViewModel
{
public IEnumerable<Question> Questions { get; set; }
public IEnumerable<QuestionOption> QuestionOptions { get; set; }
public int Id { get; set; }
public Nullable<int> Options { get; set; }
public string QuestionOption1 { get; set; }
public Nullable<int> QuestionOptionRanking { get; set; }
public string Question1 { get; set; }
public int QuestionTypeId { get; set; }
public Nullable<int> QuestionRanking { get; set; }
public string Answer { get; set; }
}