The N+1 Select problem

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:

  1. A list of entities was returned that will be further iterated to perform some additional operation.
  2. 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 for N number of items returned in the first step
  3. This makes the application perform N+1 Select (N for the iterations and 1 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 ...

Get Mastering Entity Framework Core 2.0 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.