Entity Framework 6 Eager Loading

By | December 30, 2016
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInDigg thisPin on Pinterest

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:

ASP.NET MVC Jobs [Updated Daily]

Top ASP.NET MVC Jobs

Senior Software Quality Assurance Engineer
Source: OneStream Software
Details: C#, Visual Basic, SQL Server, Web Services, WCF, WPF, Silverlight, XAML, XML, ASP.NET, MVC, HTML5, JavaScript, and CSS....  More
1 day ago

Stratford, CT 23-March-2017

Sr/Lead Software Engineer – C#/.Net/SQL Server – Web Services
Source: Indeed
Details: 5+ years’ experience in server technologies such as .Net, ASP.Net, ASP.Net MVC, C#, Node.js, ASP 2.0., LDAP, Active Directory.*....  More
4 days ago

Boston, MA 20-March-2017

Senior Dot Net Developer
Source: Indeed
Details: Involved in SDLC process using the ASP.NET MVC architecture. \*\*We are not looking for students enrolled/just completed education in USA....  More
9 days ago

Redmond, WA 15-March-2017

Full Stack Web Developer (ASP.NET MVC, C#)
Source: Indeed
Details: *Title: Full Stack Web Developer* *Location: Redmond, WA* *Duration: 6 months (will extend)* *Description: * Full stack front end web developer with...  More
14 days ago

Redmond, WA 10-March-2017

Junior .NET Developer
Source: NIC
Details: MVC. In-depth experience with C#, ASP.NET and MVC. Junior .Net Developer Position....  More
1 day ago

Baton Rouge, LA 23-March-2017

SQL Server DBA/Developer
Source: Indeed
Details: Ability to code in C#.NET/VB.NET and Exposure to ASP.NET, MVC, IIS, SharePoint. Long-Term/Full-time....  More
8 days ago

Latham, NY 16-March-2017

Developer - Web - Jr
Source: Kaiser Permanente
Details: C#, Angular JS, Bootstrap, Asp.net MVC, Web API, Entity Framework. This is highly responsible work maintaining and maturing web presence, both Internet and...  More
4 days ago

Pasadena, CA 20-March-2017

.NET Developer
Source: Indeed
Details: _ ASP.NET, MVC, WebAPI, jQuery, AngularJS. The role is responsible for collaborating with team members to design, code and maintain client-facing web...  More
1 hour ago

Addison, TX 24-March-2017

.NET backbone.js/Marionette.js Developer in Cleveland, OH
Source: Indeed
Details: Position: .NET backbone.js/Marionette.js Developer Location: Cleveland, OH Duration: 6-12 Months Client : Hexaware Technologies *Job Description: * *  More
4 hours ago

Cleveland, OH 24-March-2017

Full Stack .Net Developer (USC OR GC) Local only.
Source: Indeed
Details: 4+ years of experience with ASP.Net MVC. Bachelor’s degree preferably in Comp Sci or a related engineering degree....  More
5 hours ago

Houston, TX 24-March-2017

.Net Developer
Source: Indeed
Details: Experience with C#, .NET, Entity, MVC, Web API, HTML, CSS, JavaScript/jQuery, SQL. 2+ years of experience with C# (especially ASP.NET MVC, Web API, and Entity)....  More
8 hours ago

Louisville, KY 24-March-2017

Certified Microsoft .NET Web Developer
Source: Indeed
Details: The project includes .NET MVC web applications with heavy use of JavaScript, jQuery and Kendo UI components....  More
9 hours ago

Madison, WI 24-March-2017

Net Developer
Source: Indeed
Details: Advanced knowledge in building and deploying .NET based web applications using ASP.NET, ASP.NET MVC, WCF, and WebAPI. Hi,....  More
10 hours ago

Charlotte, NC 24-March-2017

.NET Developer
Source: Indeed
Details: 5 or more years building Web application using ASP.NET MVC. My client, an internationally renowned, full-service media agency located Downtown Chicago, is...  More
30+ days ago

Chicago, IL 07-February-2017

Certified .Net Developer
Source: Indeed
Details: The project includes .NET MVC web applications with heavy use of JavaScript, jQuery and Kendo UI components....  More
1 day ago

Madison, WI 23-March-2017

.Net Developer
Source: Resort Hospitality Solutions
Details: Create and maintain web applications based on a Microsoft web stack including C#, jQuery, Azure, ASP.Net MVC and ASP.Net Web Forms....  More
1 day ago

Asheville, NC 23-March-2017

Full Stack .NET Developer
Source: Forte Group
Details: Experience with ASP.NET, MVC and .NET Framework; One of the largest technology providers is currently looking for a Full Stack .NET Developer to join their team...  More
1 day ago

Chicago, IL 60606 23-March-2017

.Net Developer
Source: Resort Hospitality Solutions
Details: Create and maintain web applications based on a Microsoft web stack including C#, jQuery, Azure, ASP.Net MVC and ASP.Net Web Forms....  More
1 day ago

Duluth, GA 23-March-2017

Certified Microsoft .NET web Developer II (Job ID: WISCJP00011321)
Source: Indeed
Details: Project Duties include requirements analysis, design, front-end web application development, testing, code reviews, implementation and mentoring a team in the...  More
1 day ago

Madison, WI 23-March-2017

.NET Developer
Source: Procentrix
Details: .NET, C#, C++, ASP.NET, Ajax, jQuery, MVC, , WCF, Sybase SQL Anywhere/SQL Server programming. Developing custom services, components, or modules using ASP.NET...  More
2 days ago

Washington, DC 22-March-2017

Full stack ASP.NET Developer
Source: Indeed
Details: MVC:. Proficiency in ASP.NET MVC 5 and C#. Our client has immediate full-time position available for skilled Dull Stack ASP.NET MVC 5/C# Web Application...  More
2 days ago

Somerset, NJ 22-March-2017

Sr .Net Full stack Developer
Source: Indeed
Details: Involved in SDLC process using the ASP.NET MVC architecture. Are you passionate self-driven job seeker who can a lead in making world class software at a full...  More
22 days ago

Seattle, WA 02-March-2017

.NET Developer
Source: Bank of America
Details: Job Description: Develop core credit and banking software solutions for the Global Wealth Management business and clients, Analyze business and technical  More
3 hours ago

Pennington, NJ 08534 24-March-2017

Dot Net Developer
Source: Indeed
Details: Hands on experience with Infrastructure and Networks, ASP.NET MVC Web API, Oracle PL/SQL, Hybrid NoSQL and Relational Databases, RESTful web services, JSON...  More
2 days ago

Columbia, MD 22-March-2017

.NET DEVELOPER
Source: Indeed
Details: Angular 2 or JS, ASP.NET MVC 4.0 with a C# back-end (uses ASP.NET Web API 2 for the API, also written in C#). LOCAL CANDIDATES ONLY, PLEASE DO NOT REPLY IF NOT...  More
3 days ago

Cherry Hill, NJ 21-March-2017
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInDigg thisPin on Pinterest