I tried searching but couldn't find an exact answer to this on docs.microsoft at: https://learn.microsoft.com/en-us/ef/core/querying/related-data#eager-loading
I have this bit of code:
await MyDbContext.Users.Where(u => u.Id == Id).Include(u => u.UserContacts).ThenInclude(uC => uC.Contact);
The return type is of type User and Contact is also of type User.
When I debug and step through, it seems like all the Contacts of the required User are loaded, as well as all their Contacts, and then all their Contacts, and so on.
Question:
- Is this expected behavior for EF and if so, doesn’t this impact performance, having to look up the DB to such depths?
- Is there a way for me to specify a kind of 'max depth'?
The closest match to what I'm asking here that I cam across was probably this SO thread: How does Entity Framework work with recursive hierarchies? Include() seems not to work with it