Lazy Loading vs Eager Loading

前端 未结 8 1303
予麋鹿
予麋鹿 2020-11-27 10:36

Lazy loading in Entity Framework is the default phenomenon that happens for loading and accessing the related entities. However, eager loading is referred to the practice of

8条回答
  •  眼角桃花
    2020-11-27 10:46

    // Using LINQ and just referencing p.Employer will lazy load
    // I am not at a computer but I know I have lazy loaded in one
    // query with a single query call like below.
    List persons = new List();
    using(MyDbContext dbContext = new MyDbContext())
    {
        persons = (
            from p in dbcontext.Persons
            select new Person{
                Name = p.Name,
                Email = p.Email,
                Employer = p.Employer
            }).ToList();
    }
    

提交回复
热议问题