Disable AutoDetectChanges on Entity Framework Core

This is what I'm familiar with, from the docs:

var blogs = context.Blogs
    .AsNoTracking()
    .ToList();

Ref: https://docs.microsoft.com/en-us/ef/core/querying/tracking


I think the way I've done it before is when you register your DBContext you can turn it off so that you don't have to add it to every query.

Off the top of my head and don't have code ex. to reference right now so I could be wrong

services.AddDbContext<YourDbContext>(options =>
{
    options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
});

EDIT: Found it. https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.dbcontextoptionsbuilder.usequerytrackingbehavior?view=efcore-3.1

Pretty sure this is what you're looking for


What you have tried

_context.Configuration.AutoDetectChangesEnabled = false;

is for EF6.

The corresponding EF Core option AutoDetectChangesEnabled is property of the ChangeTracker associated with the DbContext, so the corresponding code is

_context.ChangeTracker.AutoDetectChangesEnabled = false;