In 5.0 RC1 I get lots of warnings logged like this:
warn: Microsoft.EntityFrameworkCore.Query[20504]
Compiling a query which loads related collections for more than one collection navigation property either via 'Include' or through projection but no 'QuerySplittingBehavior' has been configured. By default EF Core 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))
If I actually follow the help and call ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning)) I will get an exception thrown to identify the queries. This is good.
However, some of these identified queries are using AutoMapper ProjectTo. If I actually try to use AsSplitQuery() on them I will get another exception.
InvalidOperationException: The query has been configured to use 'QuerySplittingBehavior.SplitQuery' and contains a collection in the 'Select' call, which could not be split into separate query. Please remove 'AsSplitQuery' if applied or add 'AsSingleQuery' to the query.
I believe the warning only should be logged for queries where it is actually possible to use AsSplitQuery().
As the second exception message says, explicitly put AsSingleQuery
First warning is about default behavior which was not configured by user. It does not necessarily say that user has to use AsSplitQuery.
Aha, I understand.
But by explicitely marking the query AsSingleQuery, wouldn't this prevent me from ever getting the AsSplitQuery benefit in case this gets implemented for ProjectTo-queries in the future?
You can also suppress the warning so when you remove that in future it will start to warn again for queries which can use split queries. Or you can configure default behavior to be split query and apply AsSingleQuery on queries which does not work so in future you only need to verify queries with AsSingleQuery operator.
Thanks, I get it. I will default for now on QuerySplittingBehavior.SingleQuery since 90% of our queries are projected using AutoMapper.
I'll close this, feel free to tag as question.
I'm getting the same split query error when I use .Select() in an AutoMapper map like this:
CreateMap<EFModel, DTO>()
.ForMember(dest => dest.ICollectionOfInts,
opts => opts.MapFrom(
src => src.RelatedCollection.Select(r => r.Id)
)
)
Error:
InvalidOperationException: The query has been configured to use 'QuerySplittingBehavior.SplitQuery' and contains a collection in the 'Select' call, which could not be split into separate query. Please remove 'AsSplitQuery' if applied or add 'AsSingleQuery' to the query.
Is it not possible to use split queries with .Select() via AutoMapper?
Is this related to/caused by #21234?
@mikeroque - That is correct.
OK, thanks.