title: OriginalValues cannot be used for entities in the Added state
body: <p>I am using Entity Framework to build an web application, the database is created on startup and my seed method adds some entities to the database without any problem. Also the retrieve of the entities is working without problems.</p>
  
  <p>My problem is that if I try to create an entity from my UI layer, I come across the error <code>OriginalValues cannot be used for entities in the Added state</code>. The exception is not thrown to the UI, but I found it when I digged around from the problem.</p>
  
  <p>I happens in my:</p>
  
  <pre><code>public virtual TEntity Add(TEntity entity)
  {
      var entry = _context.Entry(entity);
      entry.State = EntityState.Added;
      _dbSet.Add(entity);
  
      return entity;
  }
  </code></pre>
  
  <p>Screenshot:</p>
  
  <p><img src="https://i.stack.imgur.com/Ro0LO.png" alt="enter image description here"></p>
  
  <p>The entity is very small and the mappings:</p>
  
  <pre><code>public abstract class EntityBase
  {
      public int Id { get; set; }
  }
  
  public class AccessCode : EntityBase
  {
      public string Code { get; set; }
      public int UsageCount { get; set; }
  }
  
  public class AccessCodeMapping : EntityTypeConfiguration&lt;AccessCode&gt;
  {
      public AccessCodeMapping()
      {
          // Table
          ToTable("AccessCode");
  
          // Primary key
          HasKey(x =&gt; x.Id);
  
          // Properties
          Property(accesscode =&gt; accesscode.Code).IsRequired().HasMaxLength(256);
          Property(accesscode =&gt; accesscode.UsageCount).IsRequired();
      }
  }
  </code></pre>
  
  <p>And this is how I create a test access code for demo purpose</p>
  
  <pre><code>var ac = new AccessCode {Code = "321", UsageCount = 0};
  _accessCodeService.Create(ac);
  _unitOfWork.Save();
  return View("Login");
  </code></pre>
  
  <p>Can anyone figure out why this error is occurring? I'm lost. :-)</p>
  
  <p>P.s Let me know if there is some pieces of code you wish to see.</p>