Is Recursive Hierarchy LINQ possible without performance hit or multiple DB calls?
Suppose I have a
ToDo
Entity that has many sub ToDo
s. Is it possible to get the whole tree structure without any performance hit?8 Replies
Yep
.Include()
or, preferably, .Select()
For example
Same goes for recursive
Although... with recursive hierarchies you need the .Select()
IIRC, using .Include()
can lead to some shenanigansBy recursive I mean that I get subtasks of subtasks of subtasks of ...
you can probably include inner properties if you can loop through them
and call Include() ThenInclude() passing an Expression<Func<T,object>>
the above example from zzzz does this
but won't the has a hit on performance?
it will in the time it takes to iterate through each property
it is will have a time complexity problem
the easiest way to to what you want is probably using an expression and apply a select
How does a recursive select works?
well i am not sure I supose it select those entities within the select clause internally depending on the navigation property and based on the modelBuilder configuration it uses those mapped entities?