简体   繁体   中英

Entity Framework 5 dynamic proxy lazy loading: Does accessing null navigation property hit database everytime?

This states:

Once an entity has been loaded, any further queries for the entity will load it directly from the Object State Manager, whether you are using lazy loading or eager loading.

If I lazy load an entity using a navigation property of a proxy root entity and that navigable entity exists in the database, then all subsequent calls for that navigable entity will not result in a database hit because it has already been loaded.

Am I right in assuming that if I attempt to lazy load an entity(or collection) using navigation properties from a root entity proxy and it does not exist in the database -- and therefore returns null or an empty collection -- that all subsequent attempts to lazy load the same entity from the same root entity always results in a database hit?

No, it will not. The IsLoaded property in DbCollectionEntry<TEntity, TElement> and DbReferenceEntry<TEntity, TProperty> is used to figure out if loading needs to happen, the actual value, whether null or not, is irrelevant.

否,因为它将已经加载了null / empty集合值。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM