Folks, Explanation for each can be found in dozen hits. But I thought of writing those three in very simple terms.
As you know Lazy, Eager and Explicit Loading are used for data loading in Entity Framework.
Here comes the simple explanation. Let's take again a very simple example.
The explanation of the depicted diagram is; each Department offers one or many courses and each Course is offered by single department. And therefore we get the Courses as the navigation property into the Department class.
Let's write a code snippet.
First foreach for all Department rows and second foreach for Course rows related to Department i.
Let's write eager loading code snippet.
Includes create a join, rest is understandable.
Lazy and Explicit both called Deferred Loading. Typically Explicit method you use when the Lazy loading is off. One scenario where you should turn off lazy loading off is during serialization. Serialization and Lazy loading don't mix well. Serialization generally works by accessing each property on an instance of a type and property access triggers lazy loading & those lazy loaded entities are serialized and so on.
I could not get in touch with you all for sometime but I am back now again. Please keep your questions posted and I will try to resolve.
Good day Devs!
As you know Lazy, Eager and Explicit Loading are used for data loading in Entity Framework.
Here comes the simple explanation. Let's take again a very simple example.
The explanation of the depicted diagram is; each Department offers one or many courses and each Course is offered by single department. And therefore we get the Courses as the navigation property into the Department class.
Lazy Loading?
When the first entity is read, the related data is not retrieved. However the first time you attempt to access a navigation property the data required for that navigation property is automatically retrieved. One for the entity itself and one for each time that related data.Let's write a code snippet.
First foreach for all Department rows and second foreach for Course rows related to Department i.
Eager Loading?
When the entity is read, the related data is retrieved along with it. Typically results in a single join query that retrieves all the data needed.Let's write eager loading code snippet.
Includes create a join, rest is understandable.
Explicit Loading?
This is similar to Lazy loading except that you explicitly retrieve the related data in code. It doesn't happen automatically. When you access navigation property you load related data manually by getting the object state manager for an entity and calling the Collection.Load method for collections or the Reference.Load for properties.
I could not get in touch with you all for sometime but I am back now again. Please keep your questions posted and I will try to resolve.
Good day Devs!
No comments:
Post a Comment