Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

EF Core 'ConfigureWarnings(w => w.Throw(RelationalEventId.MultipleCollectionIncludeWarning))'

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading