Entity framework 在实体框架中使用单个.Include()加载相关实体?
是否有更好的方法加载所有相关实体 下面是ScholarshipRequest类,其中还包括奖学金、身份、学生、课程和用户Entity framework 在实体框架中使用单个.Include()加载相关实体?,entity-framework,linq,lazy-loading,eager-loading,Entity Framework,Linq,Lazy Loading,Eager Loading,是否有更好的方法加载所有相关实体 下面是ScholarshipRequest类,其中还包括奖学金、身份、学生、课程和用户 public class ScholarshipRequest { public int Id { get; set; } public int Year { get; set; } public Status Status { get; set; } public DateTime Applicatio
public class ScholarshipRequest
{
public int Id { get; set; }
public int Year { get; set; }
public Status Status { get; set; }
public DateTime ApplicationDate { get; set; }
public DateTime ActionDate { get; set; }
public Scholarship Scholarship { get; set; }
public Program Program { get; set; }
public Student Student { get; set; }
public User User { get; set; }
}
我只是在这里发布奖学金课程,其他的都差不多
public class Scholarship
{
public int Id { get; set; }
public string Name { get; set; }
}
下面的代码工作正常,但是有没有更好的方法可以使用单个.Include()加载所有代码,或者是其他方法?
ScholarshipRequestRepository repo = new ScholarshipRequestRepository(dBContext);
List<ScholarshipRequest> stdList = repo.Collection()
.Include("Status").Include("Student").Include("User").Include("Scholarship")
.Where(x => x.User.Id == userId).ToList();
ScholarshipRequestRepository repo=新的ScholarshipRequestRepository(dBContext);
列表stdList=repo.Collection()
包括(“身份”)。包括(“学生”)。包括(“用户”)。包括(“奖学金”)
.Where(x=>x.User.Id==userId).ToList();
简短回答:否。旁注:建议使用lambda版本的Include
@GertArnold延迟加载如何?这是一种不同的加载策略,与Include
@GertArnold完全不同,因此可以使用该方法而不是使用Include
一次性加载所有相关实体吗?