I have a fairly deep object graph and would like to eagerly load the entire graph.
I’m aware that I can eagerly load specific navigation properties using .Include().
However, that seems fragile (if I add a navigation property, I must also add an additional .Include) and requires (in my case) quite a few .Include() statements.
Is there a way to instruct EF to eagerly load the entire object graph?
You must manually include every navigation property you want to eager load. EF doesn’t provide any built in way to include all.
It is less fragile than automagic include of everything. Such feature would just cause too many problems because in many cases it would eager load navigation properties unexpectedly.
As a workaround you can create some custom extension method which will explore EF metadata of your entity types and add
Includecall for every navigation property in your graph.There are several proposed features for improving eager loading in EF. You can go through them, upvote features you see valuable or propose a new one.