title: An object with the same key already exists in the ObjectStateManager. The existing object is in the Unchanged state
body: <p>I am trying to insert a list of entities of type foo into table TB_FOO. </p>
  
  <pre><code>    Public Sub Insert(ByVal _lstFoo As List(Of TB_FOO))
  
      Try
        For i As Integer = 0 To _lstFoo.Count - 1
          Dim foo As TB_FOO = _lstFoo(i)        
          _MyEntityManager.AddToTB_FOO(foo)
        Next
        _MyEntityManager.SaveChanges()
        _MyEntityManager.AcceptAllChanges()
      Catch ex As Exception
        Debug.WriteLine(ex.StackTrace)
      End Try
  
    End Sub
  </code></pre>
  
  <p>In the foo object there are 2 relationships. One is to the entity TB_FOO2 which is an object that was just inserted earlier in the code and another is TB_FOO3 which was selected from the database. </p>
  
  <p>On the first iteration of the loop when it arrives to <code>_MyEntityManager.AddToTB_FOO(foo)</code> it throws the error </p>
  
  <blockquote>
    <p>An object with the same key already
    exists in the ObjectStateManager. The
    existing object is in the Unchanged
    state. An object can only be added to
    the ObjectStateManager again if it is
    in the added state.</p>
  </blockquote>
  
  <p>Any ideas why this error is thrown?</p>