title: The changes to the database were committed successfully, but an error occurred while updating the object context
body: <p>I have a winforms application that uses EF5, .NET 4, and SQL Server 2008.  I have the following table\entity in the database.  The T-SQL to create the tables is shown below.</p>
  
  <pre><code>CREATE TABLE [Admin].[StandardTerms](
      [StdTermID] [int] IDENTITY(1,1) NOT NULL,
      [Name] [nvarchar](50) NOT NULL,
      [Description] [nvarchar](100) NOT NULL,
   CONSTRAINT [PK_StandardTerms] PRIMARY KEY CLUSTERED 
  (
      [StdTermID] ASC
  )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>I use a BindingSource object on the form which is linked to a data grid that allows the users to create new standard terms.  When a user creates a new standard term and tries to save it, I get the following 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: 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.</p>
  </blockquote>
  
  <p>The primary key for the standard term table is an automatically generated integer.  I have checked the SSDL and made sure that the StoreGeneratedPattern is defined on the entity.</p>
  
  <pre><code>&lt;EntityType Name="StandardTerms"&gt;
      &lt;Key&gt;
          &lt;PropertyRef Name="StdTermID" /&gt;
      &lt;/Key&gt;
      &lt;Property Name="StdTermID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" /&gt;
      &lt;Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="50" /&gt;
      &lt;Property Name="Description" Type="nvarchar" Nullable="false" MaxLength="100" /&gt;
  &lt;/EntityType&gt;
  </code></pre>
  
  <p>The strange thing is that this only happens when I create a standard term from the grid.  I can use my repository to create one and it works just fine.  I can even create the exact same binding source structure and it works without the error.  At this point I am stumped.  Does anyone have any ideas on what might be going on here?</p>