Skip to content

Instantly share code, notes, and snippets.

Created June 14, 2014 09:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Temporary disabling of change tracking in Entity Framework
public sealed class NoChangeTracking : IDisposable
private readonly DbContext _dbContext;
private readonly bool _initialAutoDetectChangesValue;
public NoChangeTracking(DbContext dbContext)
if (dbContext == null) throw new ArgumentNullException("dbContext");
_dbContext = dbContext;
_initialAutoDetectChangesValue = dbContext.Configuration.AutoDetectChangesEnabled;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1063:ImplementIDisposableCorrectly")]
public void Dispose()
private void SetChangeDetection(bool setting)
_dbContext.Configuration.AutoDetectChangesEnabled = setting;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment