Subscribe to our insights, updates, and tech news

Thank you!
Coming to your inbox soon.

Why Work with Eager Loading in Entity Framework Core 6

27 July 2021

6 minute read

Eager Loading in Entity Framework Core 6
Webinar Everything you need to know about .NET 6 WATCH ON DEMAND
Modernizing UX/UI design in Healthcare GET YOUR GUIDE
How a Global Health Organization got from Old-school to Modernized GET THE CASE STUDY

Recently we had an interesting client project that we’d like to share with you in this blog post. We were tasked to build a web application in which the client’s database contained numerous objects with a huge number of navigation properties for each. In addition, there were a lot of nested properties, that would further complicate the process. These two factors represented a tough challenge that we managed to solve.

The web application had to be developed using the .NET stack and more specifically – Progress Kendo UI controls, .NET 5, and Entity Framework Core 6 (EFC6) (See more about ASP.NET MVC Vs ASP.NET Core). Another challenge was that we were provided with a database by the client, so we had to use database-first approach. Our best practice for new projects is to advise our clients to use a code-first approach instead.

How did we handle the above-mentioned challenges related to data loading and eager loading in particular?

Well, let`s go through the 3 ways you can load data from the database in EFC6:

  • Eager loading: A process in which the related data is loaded from the database as part of the initial query.
  • Lazy loading: The related data is transparently loaded from the database when the navigation property is accessed.
  • Explicit loading: The related data is explicitly loaded from the database at a later stage.

After thorough testing and research, the team decided to go with the Eager Loading option implemented in EFC 6.

Why did we choose Eager Loading?

  1. We needed to send chunks of data (not all objects at once but part of the objects with all their relevant properties loaded) on the load page event.

  2. There were heavily nested properties with depth of around 7 levels/layers.

  3. Entity Framework have a build-in feature to automatically build and manage navigation properties (also known as relationship fix-up) even reuse them if they were loaded before and that without the need to access the database again.

Let’s dive deeper into EFC 6 Eager Loading

EFC 6 offers us a handy for binding code to database relationships and this is possible by using the “. include” statement at the Data loading layer. Microsoft have provided a perfect example, which you can check here. After going through the example, another of our challenges is described and solved as well - the multiple-level issue. An example of that issue is: Customer contains a list of invoices, and each invoice contains a list of items.

EFC6 solves that by using the “.ThenInclude” method. This is how we managed to achieve building high-performance, durable and stable application using .NET 5 and EFC6.

Lastly, my personal experience

My personal experience in working with EFC6 was very positive as the scaffolding of the database worked perfectly, the generated model was easy to use and understand. The built-in features supported all my needs, giving me the chance to focus more on the front-end part of the project instead of spending more time on database and service layer.

If there’s anything else that comes to your mind as part of a potential solution, or you need help building the right architecture for your data transfers, please, don’t hesitate to get in touch! We’ll be glad to help you identify the critical points and follow the right path through solving the challenge.


.net stack

Progress kendo ui controls

.net 5

Entity framework core 6 (efc6)

Lachezar Kamburov
Lachezar Kamburov

Lachezar is а senior software developer in the field of code infrastructure and data science. He is part of Resolute Software team of experienced and talented technology professionals. With almost 10 years of experience, he is confident in delivering reliable solutions to the clients and keeping them happy.

We forge open, long-lasting partnerships with our customers.

Let us do great work together

post stamp
Please enter your first name
Please enter your last name
Please enter your company
Please enter a valid email
The phone number is invalid
We kindly ask you to accept our Privacy Notice when reaching out
Secured with ReCAPTCHA. Privacy Policy and Terms of Service.
1305 Barnard St # 839,
Savannah, GA 31401, USA
Dusartstraat 46hs, 1072HT,
Amsterdam, Netherlands
141 Tsarigradsko shose Blvd
1784 Sofia, Bulgaria

We forge open, long-lasting partnerships with our customers.

Subscribe to our insights

Subscribe to receive insights, updates and tech news from the Resolute team.

You are now subscribed to Resolute's insights!

Thank you!