I have two objects that have a many to many relationship with each other.
I'm using Entity Framework in a Database First approach.
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.
The code to access the objects uses a generic approach, where entities is my 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.
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? Sorry if this is too "newbish" of a point
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.