On running my ASP.NET Core 7 API, I get a warning
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))’.
Where do I actually put that call to ConfigureWarnings() though?
>Solution :
Where do I actually put that call to ConfigureWarnings() though?
Depends on how you are setting up the database context. This is method defined on the DbContextOptionsBuilder. If you use the "usual" DI approach then it goes in the Action<DbContextOptionsBuilder> optionsAction call for the AddDbContext/AddDbContextFactory/AddDbContextPool/AddPooledDbContextFactory:
services.AddDbContext<SomeContext>(builder => builder
.UseSqlServer() // UseYourDbEngine
.ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning)));
Note that you can also enable the query splitting either on per query basis with .AsSplitQuery() or globally with UseQuerySplittingBehavior.