鉴于以下情况:
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 对象。
有没有办法我可以只包含课程而不取回 Department 对象。例如,我可以只包括一个级别(课程)。