我用下面的代碼段有問題:如何在實體框架中實現雙重包含?
public class Course
{
[Key]
public Guid CourseId { get; set; }
public Subject CourseSubject { get; set; }
public List<Student> CourseAttendeeStudents { get; set; }
public Teacher CourseTeacher { get; set; }
public Course()
{
CourseNotes = new List<CourseNote>();
CourseAttendeeStudents = new List<Student>();
CourseSubject = new Subject();
CourseId = Guid.NewGuid();
}
}
我需要收集有關所有課程的所有信息,所以我做了以下內容:
var coursed = db.Courses.Include(p=>p.CourseAttendeeStudents).Include(p=>p.CourseTeacher);
然而,學生和教師包含另一個在自己內部列出。 我怎麼可以這樣做:
var coursed = db.Courses.Include(p=>p.CourseAttendeeStudents.Include...).Include(p=>p.CourseTeacher.Include...);