title: Member 'CurrentValues' cannot be called for the entity of type 'MyTable' because the entity does not exist in the context
body: <p>I have a MVC application that used Entity Framework v6.0. Whenever a change is made to the <code>DbContext</code>, I override the <code>SaveChanges()</code> method and record the modifications in an audit log. Below is code for part of the audit log recording process:</p>
  
  <pre class="lang-c# prettyprint-override"><code>public override int SaveChanges()
  {
      var ChangesEntities = ChangeTracker.Entries().Where(e =&gt; e.State == EntityState.Deleted
          || e.State == EntityState.Modified
          || e.State == EntityState.Added).ToList();
  
      foreach (DbEntityEntry entry in ChangesEntities)
      {
          if (entry.State == EntityState.Modified)
          {
              SetCorrectOriginalValues(entry);
          }
  
          ...
      }
  
      ...
  
      return base.SaveChanges();
  }
  
  void SetCorrectOriginalValues(DbEntityEntry Modified)
  {
      var values = Modified.CurrentValues.Clone();
      Modified.Reload();
      Modified.CurrentValues.SetValues(values);
      Modified.State = EntityState.Modified;
  }
  </code></pre>
  
  <p>This code usually works, however, when I attempt to make a specific update, I am getting the following error:</p>
  
  <p><strong>Exception Message:</strong></p>
  
  <pre class="lang-none prettyprint-override"><code>Member 'CurrentValues' cannot be called for the entity of type 'MyTable' because the
  entity does not exist in the context.
  To add an entity to the context call the Add or Attach method of DbSet.
  </code></pre>
  
  <p><strong>Exception Stack Track:</strong></p>
  
  <pre><code>at System.Data.Entity.Internal.InternalEntityEntry.get_CurrentValues()
  at System.Data.Entity.Infrastructure.DbEntityEntry.get_CurrentValues()
  at MyDatabaseName.DataLibrary.MyDatabaseEntities
      .SetCorrectOriginalValues(DbEntityEntry Modified)
  at MyDatabaseName.DataLibrary.MyDatabaseEntities.SaveChanges()
  ...
  </code></pre>
  
  <p>What does the exception message mean? When and why would <code>CurrentValues</code> not be able to be called? What does is mean that entity does not exist in the context?</p>
  
  <p>In MyDatabaseEntities.Context.cs, which extends <code>DbContext</code>, 'MyTable' seems to exist:</p>
  
  <pre class="lang-c# prettyprint-override"><code>public virtual DbSet&lt;MyTable&gt; MyTables { get; set; }
  </code></pre>
  
  <p>I checked the Entity Framework model diagram, and 'MyTable' exists there to.</p>