title: The changes to the database were committed successfully, but an error occurred while updating the object context in c#
body: <pre><code>TruncateData("Order");
  TruncateData("Customer");
  
  context.Customers.Add(new Customer(fields));
  //  context.Employees.Add(new Employee(fields));
  context.SaveChanges();
  
  fillComboBox();
  
  public void TruncateData(String table)
  {
      context.Database.
          ExecuteSqlCommand
          ("Delete from [dbo].[" + table + "]" + $" DBCC CHECKIDENT('{table}', RESEED, 0)");
      context.SaveChanges();
  
  }
  </code></pre>
  
  <p>I'm reading file from csv files to database in C# and I am uploading to database using Entity Framework. Before inserting the values I'm truncating the data so it primary key starts from 1 every time. But I am getting this error. </p>
  
  <p>Here s my error:</p>
  
  <blockquote>
    <p>The changes to the database were committed successfully, but an error occurred while updating the object context. The <code>ObjectContext</code> might be in an inconsistent state. Inner exception message: Saving or accepting changes failed because more than one entity of type <code>ProjectTeam03ElectricStore.EF_Classes.Customer</code> have the same primary key value. Ensure that explicitly set primary key values are unique. Ensure that database-generated primary keys are configured correctly in the database and in the Entity Framework model. Use the Entity Designer for Database First/Model First configuration. Use the <code>HasDatabaseGeneratedOption</code> fluent API or <code>DatabaseGeneratedAttribute</code> for Code First configuration.</p>
  </blockquote>