, EF4.1 :
퀴즈 화면을 구축, 나는 세 단체에 가입하고 각 단계는 많은 질문을 할 수있는 단계, 질문, 응답3 개의 엔티티를 결합하는이 LINQ에 대해 (왼쪽/오른쪽) 외부 조인을 사용하는 방법? MVC 3를 사용하여
를, 각 질문은 수 일 또는 전혀 응답
내 문제는 내 쿼리에 응답이없는 경우 질문없이 단계를 반환합니다. 이 LINQ에 외부 조인 (왼쪽/오른쪽)을 통합하려면 어떻게해야합니까?
var steps = from s in db.Steps
join r in db.Responses.Where(x => x.ReviewID == id)
on s.StepID equals r.Question.StepID into g
orderby s.StepOrder
select new Quiz
{
StepID = s.StepID,
Title = s.Title,
Results = from x in g
orderby x.Question.DisplayOrder
select new Result
{
QuestionID = x.Question.QuestionID,
DisplayOrder = x.Question.DisplayOrder,
Choices = x.Question.Choices,
ControlType = x.Question.ControlType,
QuestionText = x.Question.QuestionText,
AnswerValue = x.AnswerValue
}
};
질문 모델 :
public class Question
{
public Question()
{
this.Responses = new List<Response>();
}
public int QuestionID { get; set; }
public string QuestionText { get; set; }
public Nullable<bool> Required { get; set; }
public int DisplayOrder { get; set; }
public int StepID { get; set; }
public Nullable<int> DataType { get; set; }
public Nullable<int> ControlType { get; set; }
public string Choices { get; set; }
public Nullable<int> MaxLength { get; set; }
public virtual ICollection<Response> Responses { get; set; }
public virtual Step Step { get; set; }
public string NumberedQuestion
{
get { return String.Format("{0}. {1}", DisplayOrder, QuestionText); }
}
}
응답 :
public class Response
{
public int ResponseID { get; set; }
public int UserID { get; set; }
public int QuestionID { get; set; }
public string AnswerValue { get; set; }
public int ReviewID { get; set; }
public virtual Question Question { get; set; }
}
단계 :
public Step()
{
this.Questions = new List<Question>();
}
public int StepID { get; set; }
public int ReviewID { get; set; }
public string Title { get; set; }
public string Description { get; set; }
public int StepOrder { get; set; }
public virtual ICollection<Question> Questions { get; set; }
당신은 세 가지 entites이 말한 ... 우리와 함께 위 코드는'question' 엔티티를 공유하시기 바랍니다 ... –
나는 감사합니다, 나는 help..works 큰 감사 – Chaka