title: Same object inserted twice with Entity Framework
body: <p>I'm wondering if it's possible (while using entity framework) to insert 2 entities with the same key?</p>
  
  <p>Say we have a model like this:</p>
  
  <pre><code>class Foo {
      Bar Bar1 { get; set; }
      Bar Bar2 { get; set; }
  }
  </code></pre>
  
  <p>Where Bar1 and Bar2 could be the same 'Bar'. For instance:</p>
  
  <p>Say we have a key inside Bar:</p>
  
  <pre><code>class Bar {
      int Key { get; set; }
  }   
  </code></pre>
  
  <p>An instance of the Foo-class could look like:</p>
  
  <pre><code>Foo.Bar1.Key == 1
  Foo.Bar2.Key == 1
  </code></pre>
  
  <p>Hence they are the same entity.</p>
  
  <p>However, if I try to insert the Foo into the database, it results in entity framework trying to add both Bar1 and Bar2 separately, which then results in an primary key violation.</p>
  
  <p>My question is this:</p>
  
  <p><strong>Is it possible to tell entity framework to skip adding Bar2 and just to add a reference to Bar1?</strong></p>