Entity Framework 6 Eager Loading

By | December 30, 2016

In this Entity Framework Tutorial, we are going to understand about an important concept related to Object Relational Mapping that is “Eager Loading” with the help of a practical example. We already have discussed eager loading at high level, and another related concept “Lazy Loading” that is opposite to Eager Loading while discussing Entity Framework Interview Questions along with more Entity Framework concepts. To see a practical example for Lazy Loading in Entity Framework, follow here.

Eager loading is the process by which a query loads related entities along with it as part of the query. It is achieved by the using the “Include” method. For example, when querying orders, eager-load their product details also in a single query.

More Practical Entity Framework Tutorial

In order to practically grasp Entity Framework, we highly recommend to go through these real time implementations:


We have created 3 entities, Category, Products and Orders. In below diagram, entities with their relationships look as:Entity Framework Tutorial Eager Loading

The class of Products will look as:

The class of order entity will look as:

Following code does the eager loading in case of products and orders:

Resultant screen will be:EF Tutorial Eager Loading

In order to create an order, we can do as:

  • Learn ASP NET MVC 5 step by step [Maruti Makwana, Corporate Trainer] 28 Lectures, 2.5 Hours Video, Intermediate Level
    Very easy to learn video series on Asp.Net MVC 5 Specially for those who are familiar with Asp.Net Web forms.
  • AngularJS for ASP.NET MVC Developers [Brett Romero] 10 Lectures, 1 hour video, Intermediate Level
    The Fastest Way For .NET Developers To Add AngularJS To Their Resume
  • ASP.NET with Entity Framework from Scratch [Manzoor Ahmad, MCPD | MCT] 77 Lectures, 10 hour video, All Level
    Latest approach of web application development
  • Comprehensive ASP.NET MVC [3D BUZZ] 34 lectures, 14 Hours Video, All Levels
    From zero knowledge of ASP.NET to deploying a complete project to production.
The screen will look as:New Product EF Tutorial

This screen will place an order of products. As we have added foreign key constraint in orders with products. So with eager loading we can load the related product details while loading orders.

EF Eager Loading Example

After reading this Entity Framework Tutorial, it will be easy to implement eager loading in our application. Follow here to understand that correctly choosing between eager-loading and lazy-loading in practical scenarios.

You are working with WebDevTutorial and building an ADO.NET Entity Framework application for a client. You need to validate the conceptual schema definition language (CSDL), store schema definition language (SSDL), and mapping specification language (MSL) files. Which Entity Data Model tool can you use? (Each correct answer presents a complete solution. Choose all that apply.)

  • A. EDM Generator (EdmGen.exe)
  • B. ADO.NET Entity Data Model Designer
  • C. Update Model Wizard
  • D. Entity Data Model Wizard
  • E. All of Above
  • F. None of Above

For a complete online test and Practice Exams on Web Technologies, Click Here.

 Correct Answer: B, D

Top Technical Interview Questions and Answers Series: