即使延迟加载不能使用,也可以通过明确的调用来延迟加载相关实体

使用DBEntryEntity来完成

using (var context = new SchoolDBEntities())
{
    //Disable Lazy loading
    context.Configuration.LazyLoadingEnabled = false;
                
    var student = (from s in context.Students
                        where s.StudentName == "Bill"
                        select s).FirstOrDefault<Student>();

    context.Entry(student).Reference(s => s.Standard).Load();
}     

 

 

using (var context = new SchoolDBEntities())
{
    context.Configuration.LazyLoadingEnabled = false;
                
    var student = (from s in context.Students
                        where s.StudentName == "Bill"
                        select s).FirstOrDefault<Student>();

    context.Entry(student).Collection(s => s.Courses).Load();
}

 

相关文章:

  • 2021-06-20
  • 2021-11-19
  • 2021-07-09
  • 2021-11-19
  • 2021-09-04
  • 2021-12-12
  • 2021-09-01
  • 2022-12-23
猜你喜欢
  • 2021-06-10
  • 2022-12-23
  • 2021-05-23
  • 2021-09-02
  • 2022-03-10
  • 2021-04-26
相关资源
相似解决方案