DbContextScope icon indicating copy to clipboard operation
DbContextScope copied to clipboard

Prevent forcing AutoDetectChangesEnabled being true if not readonly

Open warappa opened this issue 8 years ago • 0 comments

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?

warappa avatar Jul 17 '17 20:07 warappa