DbContextScope
DbContextScope copied to clipboard
Prevent forcing AutoDetectChangesEnabled being true if not readonly
Currently if AutoDetectChangesEnabled is set to false in a constructor of a DbContext, it is again set to true by DbContextCollection.Get<TDbContext>(). This is not expected.
In my current case I want to turn off AutoDetectChangesEnabled because I batch some operations and just before SaveChanges() I call ChangeTracker.DetectChanges() manually.
The original implementation by mehdime works better in this regard by only setting the value to false if readonly is true, otherwise it leaves it as-is.
if (_readOnly)
{
dbContext.Configuration.AutoDetectChangesEnabled = false;
}
Could this be changed in an upcoming version?