ReSharper
 
Get ReSharper
You are viewing the documentation for an earlier version of ReSharper.

Code Inspection: Possible multiple queries to the database for related entities (N+1 problem)

Last modified: 08 March 2021

This inspection detects the N+1 Select problem, where unnecessary database calls are made when iterating a collection.

The problem can be illustrated with the following example, where Products and Details are 2 database tables and each Product entry is linked to multiple Detail entries.

To fix this problem, ReSharper suggests using the Include feature of the Entity Framework Core, which will load all linked Detail entries right in the first query:

If the chain of navigational property calls is longer, the quick-fix will add ThenInclude as required: