Search code examples
entity-frameworkrelational-databaseeager-loading

Relational database eager loading issue in entity framework


I have a unclear understanding on relational database eager loading. My example is Children - Teacher which is a multiple relationship.My question is if we eager load children entity ,it will consist collection of teachers ,and those teachers will contain list of children ,How far this will go and how to stop from a certain level.


Solution

  • My question is if we eager load children entity ,it will consist collection of teachers ,and those teachers will contain list of children ,How far this will go and how to stop from a certain level.

    You don't need and cannot stop this cycle because this is called EF/EF Core proxy creation. This is the default behavior of EF/EF Core Eager Loading and there is no way to stop this. But you can stop self referencing loop for JSON response.

    Here is details about this:Related data and serialization in EF Core