How to say EF , Don't Load all properties!
There is an Entity with many relationships, when i say to EF load a query on a Entity, it loads all properties(OK) with relationshi开发者_开发知识库ps(i don't want)!
This is a big penalty on performance, because i just need some properties not All relationships.
How to say EF that just load entity's property and Don't load relationships (EntityCollection<TEnitity>
) ?
I want load relationships's properties by hand!
Are you sure the navigation properties are being eagerly loaded? They shouldn't be by default. Are you using POCO or Code First? If you are, then you need to make sure your navigation properties are marked "virtual". Virtual properties will be lazy loaded.
To check whether navigation properties are lazy loading or eager loading, you'll want to use a tool like SQL Profiler.
JohnnyO is correct; The default value for ObjectContextOptions.LazyLoadingEnabled is false
. However, when I create a model from the database, the default value for the model is true
. If you are using the generated EF classes, try setting this to false
.
精彩评论