我正在创建一个问卷屏幕,我需要显示带有问题的部分以及用户的回答。这是我的模型:
** 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;