Ho le seguenti classi:Come posso .Includere più di un livello in LINQ?
public class Problem : AuditableTable
{
public Problem()
{
this.Questions = new List<Question>();
}
public int ProblemId { get; set; }
public string Title { get; set; }
public virtual ICollection<Question> Questions { get; set; }
}
public Question()
{
this.Answers = new List<Answer>();
}
public int QuestionId { get; set; }
public int ProblemId { get; set; }
public virtual ICollection<Answer> Answers { get; set; }
public virtual Problem Problem { get; set; }
}
public class Answer : AuditableTable
{
public int AnswerId { get; set; }
public int QuestionId { get; set; }
public string Text { get; set; }
public virtual Question Question { get; set; }
}
voglio emettere una query come questa:
var problems = _problemsRepository.GetAll()
.Where(p => p.ProblemId == problemId)
.Include(p => p.Questions)
.Include(p => p.Questions.Answers)
.ToList();
return problems;
così posso vedere problema, domanda e risposta informazioni. Ma c'è un problema con la mia ultima inclusione e non riesco a capire come ottenere le risposte incluse.
Qualcuno può darmi qualche consiglio su questo.
Il primo 'Include' è obsoleto. Il secondo includerà anche le domande. – user2674389
@ user2674389 Aggiornato! Grazie per aver commentato che .. –