dotnet / dotnet/efcore

Multiple Include() warning: false positive for ThenInclude()?

Open
#29,665 17 comments 1 reaction 0 assignees View on GitHub
area-query customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

There is warning that protects us against inadvertent cross products. It occurs when we use multiple calls to `Include()` in a single query:

```
Compiling a query which loads related collections for more than one collection navigation,
either via 'Include' or through projection, but no 'QuerySplittingBehavior' has been configured.
By default, Entity Framework will use 'QuerySplittingBehavior.SingleQuery',
which can potentially result in slow query performance.
See https://go.microsoft.com/fwlink/?linkid=2134277 for more information.
To identify the query that's triggering this warning call
'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'.
```

We can suppress it with an explicit call to `.AsSingleQuery()` if we know what we are doing.

To my surprise, the warning _also_ pops up for `.Include(parent => parent.Child).ThenInclude(child => child.Grandchild)`.

The reason I am surprised is that this seems to give the warning whenever `ThenInclude()` is used, as if that entire method should be avoided. Moreover, an `Include()` followed by a `ThenInclude()` does not introduce a cross product and thus seems no cause for concern.

Is this a false positive?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.