title: ObjectContext Error with using .AddRange in EF 6
body: <p>I'm trying to find some help on an error I'm getting when using the .AddRange in EF 6. I'm getting the following error.</p>
  
  <pre><code>The changes to the database were committed successfully, but an error occurred while updating the object context. 
  The ObjectContext might be in an inconsistent state. Inner exception message: AcceptChanges cannot continue because 
  the object's key values conflict with another object in the ObjectStateManager. Make sure that the key values are 
  unique before calling AcceptChanges.
  </code></pre>
  
  <p>As the error states, my records are actually getting added to the table so I don't know where fix the error. </p>
  
  <p>Doing some research I found a bunch of posts where others say that it has to do with the .edmx file and a primary key on the table. Their suggestion is basically to add the PK and then rebuild the .edmx file. This doesn't fit my scenario for two reasons, one is that I'm using EF 6 with DataBase First so there isn't an .edmx file and second is that this is mapped to and Oracle 11 DB and so the identity is created with a trigger (which seems to work when I look at the added records). </p>
  
  <p>Here is my code I'm using as well as the class for the entity. </p>
  
  <pre><code>using (APIcontext db = new APIcontext())
              {
                  if (listLostTime.Count &gt; 0)
                  {
                      db.GROUND_HOURS.AddRange(listLostTime);
                      db.SaveChanges();
                  }
              }
  </code></pre>
  
  <p>And the entity class</p>
  
  <pre><code>[Table("GROUND_HOURS")]
      public partial class GROUND_HOURS
      {
          [Key]
          public decimal RID { get; set; }
  
          [Required]
          [StringLength(8)]
          public string EMP_ID { get; set; }
  
          [StringLength(2)]
          public string COMPANY_CODE { get; set; }
  
          public DateTime OCCURRENCE_DATE { get; set; }
  
          [Required]
          [StringLength(25)]
          public string PAY_CODE { get; set; }
  
          public decimal PAY_HOURS { get; set; }
  
          public DateTime INSERT_DATE { get; set; }
      }
  </code></pre>
  
  <p>I'm looking for any suggestions.</p>