Last post Aug 28, 2016 01:34 AM by Yohann Lu
Jul 26, 2016 09:43 AM|enendaveyboy|LINK
I am trying to find a better way to load big complex models using the entity framework, my current model has 180 table and errors with Out of Memory.
I currenty use includes
But whats the difference bwtween LoadProperty and Include?
Jul 26, 2016 10:20 AM|NishantMittal|LINK
Seems LoadProperty is not an available method in DbContext. But u can use include method that comes in System.Data.Entity.
Here is the syntax for the same
object.Include(p => p.Id)
Jul 26, 2016 09:17 PM|enendaveyboy|LINK
I am not sure how that helps, but thanks for the reply.
Jul 27, 2016 06:23 AM|Yohann Lu|LINK
As far as I know, Normally we load related entities using LoadProperty in the context or use Include in the Linq query. There are several ways how to load navigation properties in EF.
•Eager loading (using Include)
Include is an example of eager loading. May be you should avoid using Include if it expands multiple detail rows on a master table row.
•Explicit loading by ObjectContext.LoadProperty
Explicitly loads an object related to the supplied object by the specified navigation property and using the default merge option. The LoadProperty method must be called to achieve explicit loading when you are using POCO custom data classes
The following links for your reference.
Loading Related Entities:
Inside Entity Framework: Lazy Loading, Explicit Loading and Eager Loading:
Jul 27, 2016 08:17 PM|enendaveyboy|LINK
Thanks but thats doesn't help either, plus lazy loading is changing in EF7, none of those articles are dated, and my titles doesn't ask what are the options.
Aug 28, 2016 01:34 AM|Yohann Lu|LINK
I am trying to find a better way to load big complex models using the entity framework
You may consider using some caching in the Entity Framework.
1.Object caching – the ObjectStateManager built into an ObjectContext instance keeps track in memory of the objects that have been retrieved using that instance. This is also known as first-level cache.
By default when an entity is returned in the results of a query, just before EF materializes it, the ObjectContext will check if an entity with the same key has already been loaded into its ObjectStateManager. If an entity with the same keys is already present
EF will include it in the results of the query. Although EF will still issue the query against the database, this behavior can bypass much of the cost of materializing the entity multiple times.
2.Query Plan Caching - reusing the generated store command when a query is executed more than once.
The first time a query is executed, it goes through the internal plan compiler to translate the conceptual query into the store command. If query plan caching is enabled, the next time the query is executed the store command is retrieved directly from the
query plan cache for execution, bypassing the plan compiler.
With results caching (also known as "second-level caching"), you keep the results of queries in a local cache. When issuing a query, you first see if the results are available locally before you query.