Eager Loading and lazy Loading in Entity Framework: Easy Way to learn

Eager Loading with DBContext

Eager loading is the process, where a query for one type of entity also loads related entities as part of the query. Eager loading is achieved by use of the 'Include' method.

Eager loading use of the Include method

Below code snippet shows eager loading where Standard entity will also be loaded with Student entity using Include method.

Lazy Loading with DBContext

Lazy loading means delaying the loading of related data until you specifically request it. For example, in below code snippet, we first load all the students from the database then it will load address of particular student when we access StudentAddress entity.

Lazy Loading with DBContext

To learn more about MVC please go to the following link.

MVC Articles

Thanks.Enjoy coding and reading.

Ebook Download
View all
Learn
View all