【发布时间】:2025-03-04 00:50:02
【问题描述】:
我有一个开启延迟加载的模型类。到目前为止,我一直使用延迟加载,例如为单个学生加载他的课程集合。
如果我想加载所有已注册学生集合的所有课程,我可以使用 Include() 方法在延迟加载的属性上预先加载吗?有没有副作用?
[ForeignKey("Id")]
public virtual ICollection<Students> Students { get; set; }
public IQueryable<Students> GetCoursesWithAllStudents()
{
return db.Courses.Include(c => c.Students);
}
【问题讨论】:
-
没有问题,没有副作用。
标签: c# entity-framework entity-framework-6