Monday, 27 March 2017

Eager loading, Lazy loading and work through using DTOs

Eager Loading: use the Include method like
db.books.Include(b=>b.Related_entity);

Lazy Loading: EF automatically loads the related entity when navigation property is referenced. To enable lazy loading, make the navigation property virtual.
public virtual Author Author{get;set;}

Problem of Circular Reference during Serializing models.
When both entities have navigation property with each other, it created a problem when we serialize the models. It creates a circular object graph.

Solution:
We need to use DTO and load all data in them before returning it. 

No comments:

Post a Comment

Bevereages

Types of Beverages Fermented - yeast reacts with sugar to convert into ethyl alcohol & CO2. 4-14% Wine (red, white & rose), Cider ...