Entity Framework same primary key value error when saving changes to database
<p>In my program, I'm using Entity Framework and added a table to my <code>.edmx</code> model. I mapped the insert, update, and delete functions to only one stored procedure, my update procedure, since it is the only procedure I will be using on this table. In my program, I loop through a bunch of users getting values and adding them to the entity before finally saving the changes. </p>

<p>Start loop    </p>

<pre><code>var newGroup = new ru_Groups();

newGroup.adsPath = adsPath; 
newGroup.DisplayName = displayName; 
newGroup.Domain = domain; 
newGroup.AccountName = accountName;
newGroup.Email = email;
newGroup.GroupType = groupType;

UserEntities.ru_Groups.Add(newGroup);
</code></pre>

<p>end loop</p>

<pre><code>UserEntities.SaveChanges();
</code></pre>

<p>The problem is when I save the changes I get this error</p>

<blockquote>
  <p>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: Saving or accepting
  changes failed because more than one entity of type
  'AD.Data.ru_Groups' 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
  'HasDatabaseGeneratedOption" fluent API or
  'DatabaseGeneratedAttribute' for Code First configuration.</p>
</blockquote>

<p>Why is this happening? The ID <code>StoredGeneratedPattern</code> property is set to <code>Identity</code>, however the stored procedure which I've mapped to the <code>Update</code> function does not require an ID as a parameter, let alone a unique ID.</p>

<p>Thank you</p>