考虑以下几点:我可以限制.include通过LINQ和Entity Framework 5添加了多少级别?
public class Department
{
public int DepartmentID { get; set; }
public string Name { get; set; }
public virtual ICollection<Course> Courses { get; set; }
}
public class Course
{
public int CourseID { get; set; }
public string Title { get; set; }
public int Credits { get; set; }
public int DepartmentID { get; set; }
public virtual Department Department { get; set; }
}
如果我把懒加载关闭并发出以下命令:
var departments = _DepartmentRepository.GetAll()
.Include(c => c.courses);
然后我得到的答案与他们的内部Department对象。
有没有一种方法,我可以只包括课程,而不是回收部门对象。例如,我可以只包含一个级别(课程)。
你找到了实现这个目标的最佳方法吗?我正在努力。 – shaikhspear