[英]Lazy Loading Items in Entity Framework
I have two objects that have a many to many relationship with each other. 我有两个彼此有多对多关系的对象。
I'm using Entity Framework in a Database First approach. 我在Database First方法中使用Entity Framework。
My Database Profiler is showing that everytime I fetch one set of objects A, it loads the other set of object B for each element in A. I assumed that with lazy loading, this wouldn't happen, or that B would be fetched when accessing via the navigation property. 我的数据库分析器显示每次我获取一组对象A时,它为A中的每个元素加载另一组对象B.我假设使用延迟加载,这不会发生,或者在访问时将获取B通过导航属性。
The code to access the objects uses a generic approach, where entities is my DbContext 访问对象的代码使用通用方法,其中实体是我的DbContext
public virtual IQueryable<T> GetAll()
{
IQueryable<T> query = entities.Set<T>();
return query;
}
Both navigation properties are implemented as virtual ICollection<T>
and I have Configuration.LazyLoadingEnabled = true
explicitly set in my DbContext
constructor. 两个导航属性都实现为virtual ICollection<T>
,我在我的DbContext
构造函数中显式设置了Configuration.LazyLoadingEnabled = true
。
Am I missing something, or approaching this the wrong way? 我错过了什么,或接近错误的方式? Should I just remove the navigation properties and explicitly load what I need via other queries? 我应该删除导航属性并通过其他查询显式加载我需要的内容吗?
In the presence of the experts I am reluctant to ask this :) but would setting ProxyCreationEnabled=false on the DbContext not help in this case? 在专家在场的情况下,我不愿意这样问:)但是在这种情况下,在DbContext上设置ProxyCreationEnabled = false无济于事吗? Sorry if this is too "newbish" of a point 对不起,如果这是一个点“太新”了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.