Lazy Loading vs Eager Loading

前端 未结 8 1333
予麋鹿
予麋鹿 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:59

    I think it is good to categorize relations like this

    When to use eager loading

    1. In "one side" of one-to-many relations that you sure are used every where with main entity. like User property of an Article. Category property of a Product.
    2. Generally When relations are not too much and eager loading will be good practice to reduce further queries on server.

    When to use lazy loading

    1. Almost on every "collection side" of one-to-many relations. like Articles of User or Products of a Category
    2. You exactly know that you will not need a property instantly.

    Note: like Transcendent said there may be disposal problem with lazy loading.

提交回复
热议问题