The N + 1 Select
problem arises due to an internal data store call made by any ORM framework to perform a single operation. The problem could be outlined as follows:
- A list of entities was returned that will be further iterated to perform some additional operation.
- Assuming a navigational property is accessed inside the iteration:
- Each time an iteration tries to access the navigational property, a database hit occurs
- The hits will happen
N
times forN
number of items returned in the first step
- This makes the application perform
N+1 Select
(N
for the iterations and1
for the first call that retrieves the list), which should have been performed in a single database call.
This behavior is often termed as lazy loading in any ORM frameworks, which loads the subsequent/dependent data only when required. The lazy loading is yet to be supported by EF Core. This can be verified in the EF Core road map, which lists it as Stretch goals
, as shown in the following screenshot:
The issue...