Lazy Loading vs Eager Loading

前端 未结 8 1308
予麋鹿
予麋鹿 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 11:05

    It is better to use eager loading when it is possible, because it optimizes the performance of your application.

    ex-:

    Eager loading
    
    var customers= _context.customers.Include(c=> c.membershipType).Tolist();
    
    lazy loading
    

    In model customer has to define

    Public virtual string membershipType {get; set;}
    

    So when querying lazy loading is much slower loading all the reference objects, but eager loading query and select only the object which are relevant.

提交回复
热议问题