我正在创建一个问卷画面,我需要显示带有问题的部分以及用户的回复。这里是我的模型:如何查询有问题的部分及其答案?
** Section *****
public int SectionID { get; set; }
public string SectionText { get; set; }
** Question ****
public int QuestionID { get; set; }
public int SectionID { get; set; }
public string QuestionText { get; set; }
public bool Required { get; set; }
public int DisplayOrder { get; set; }
** Response ****
public int ResponseID { get; set; }
public int UserID { get; set; }
public int QuestionID { get; set; }
public string AnswerValue { get; set; }
public virtual Question Question { get; set; }
如何抓住这个直通LINQ或其他方式,显示如下:
Section1: User Info
Question 1. Name: Bob Smith
Question 2. Phone: 999-999-9999
Section2: User Tasks
Question 1. Role: Engineer
Question 2. Location: Baltimore
我尝试以下(DEOS不工作):
var sections = from b in db.Sections.Include(s => s.Questions.Select(q => q.Responses.Where(r => r.userId == 1))
orderby b.SectionOrder
select b;
与节你怎么链接的问题? – Ulises
我刚刚更新了我的问题。 “SectionId”在与Section关联的Question模型中缺失。 – Chaka
最后一个问题。我注意到,当没有答案时,它不返回任何问题..有没有相当于LINQ的左/右外连接?如果返回所有问题都返回? – Chaka