简体   繁体   English

实体框架5动态代理延迟加载:是否每次访问null导航属性都会命中数据库?

[英]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? 我是否正确假设,如果我尝试使用根实体代理中的导航属性来延迟加载一个实体(或集合),并且该实体(或集合)在数据库中存在-因此返回null或空集合-所有后续尝试从相同的根实体懒加载相同的实体总是导致数据库命中吗?

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. DbCollectionEntry<TEntity, TElement>DbReferenceEntry<TEntity, TProperty>IsLoaded属性用于确定是否需要进行加载,实际值(无论是否为null )无关紧要。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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