 <p>The problem is the attaching thing, use <code>Add</code> instead.</p> <p>When you do the <code>context.sample_set.Attach(s1);</code>, what it really does is create the instance of all related objects in the new context and then add them to the sample_set, that why it works.</p> <p>When you try to <code>context.sample_set.Attach(s2);</code>, it tries to create again all shared <code>samples</code>, that is why it throws the exception.</p> <p>So my suggestion to you is :</p> <pre><code>context.sample_set.Add(s1); context.sample_set.Add(s2); context.SaveChanges(); </code></pre> <p>I hope it helps.</p>