title: How do I turn off change tracking at the DbContext level in EF 4.1 RC?
body: <p>I've encountered what seems to be a common problem: I am updating values in my database, but EF is using its original in-memory copy of the object and these changed values are not reflected in the displayed data. I understand why this is, but I can't figure out a way around it.</p>
  
  <p>The most common solution seems to be to set <code>MergeOptions.NoTracking</code> to turn off change tracking completely (or use the <code>AsNoTracking()</code> extension method when querying) and force a refresh every time the object is accessed, which is fine for my purposes.</p>
  
  <p>I've got a generic base repository which my other repositories inherit from:</p>
  
  <pre><code>public abstract class RepositoryBase&lt;T&gt; where T : class
  {
      private readonly IDbSet&lt;T&gt; _dbset;
      private readonly IUnitOfWork _unitOfWork;
  
      protected RepositoryBase(IUnitOfWork unitOfWork)
      {
          _unitOfWork = unitOfWork;
          _dbset = _unitOfWork.Database.Set&lt;T&gt;();
      }
  
      public virtual IQueryable&lt;T&gt; All()
      {
          return _dbset;
      }
  
      // Some other IQueryable methods here (Query, GetByProductCode etc)
  
      public virtual T Get(long id)
      {
          return _dbset.Find(id);
      }
  }    
  </code></pre>
  
  <p>And a <code>DbContext</code> like this:</p>
  
  <pre><code>public class Db : DbContext
  {
      private IDbSet&lt;Product&gt; _products;
  
      public IDbSet&lt;Product&gt; Products
      {
          get { return _products ?? (_products = DbSet&lt;Product&gt;()); }
      }
  
      public virtual IDbSet&lt;T&gt; DbSet&lt;T&gt;() where T : class
      {
          return Set&lt;T&gt;();
      }
  
      public virtual void Commit()
      {
          base.SaveChanges();
      }
  }
  </code></pre>
  
  <p>If I change the <code>All()</code> method of my repository thus:</p>
  
  <pre><code>public virtual IQueryable&lt;T&gt; All()
  {
      return _dbset.AsNoTracking();
  }
  </code></pre>
  
  <p>I get the desired result - an update in the database is reflected when the page displaying the products is refreshed. However, I can't do this in the <code>Get()</code> method, as that extension method only works on an <code>IQueryable</code>.</p>
  
  <p>Ideally I'd like to turn this off at the <code>DbContext</code> level as I will never need change tracking, but there doesn't seem to be an obvious way to do this, and there is pretty much zero documentation on the subject (unless someone can point me to some? Please!).</p>
  
  <p>I tried adding a constructor to the <code>DbContext</code> with these configuration options disabled:</p>
  
  <pre><code>public Db()
  {
      base.Configuration.ProxyCreationEnabled = false;
      base.Configuration.AutoDetectChangesEnabled = false;
  }
  </code></pre>
  
  <p>But I must admit I'm only guessing as to what they really do (I only found them through looking at the source code), and they don't seem to have any effect anyway.</p>
  
  <p>Any help would be greatly appreciated. If more info/code would help, please let me know.</p>