title: Cannot add an entity with a key that is already in use (LINQ)
body: <p>I get this error <code>Cannot add an entity with a key that is already in use.</code> when I run the code below.</p>
  
  <p>Tables:
  <img src="https://i.stack.imgur.com/lmvIY.png" alt="enter image description here"></p>
  
  <p>What am i missing?</p>
  
  <pre><code>    private void CopyAllPageObjects(int fromPageID, int toPageID)
      {
          CMSDataContext _db = new CMSDataContext();
  
          // Copy page objects
          var originalPageObjects = (from x in _db.CMSPageObjects
                                     where x.PageID == fromPageID
                                     select x);
  
          List&lt;CMSPageObject&gt; newPageObjects = new List&lt;CMSPageObject&gt;();
          foreach (CMSPageObject po in originalPageObjects)
          {
              CMSPageObject newPageObject = new CMSPageObject();
              newPageObject.PageID = toPageID;
              newPageObject.CMSObjectID = po.CMSObjectID;
              newPageObject.Name = po.Name;
              newPageObject.Sorting = po.Sorting;
              newPageObjects.Add(newPageObject);
  
              // Copy page object attribute values
              var originalPoavs = (from x in _db.CMSPageObjectAttributeValues
                                   where x.CMSPageObjectID == po.ID
                                   select x);
  
              List&lt;CMSPageObjectAttributeValue&gt; newPoavs = new List&lt;CMSPageObjectAttributeValue&gt;();
              foreach (CMSPageObjectAttributeValue poav in originalPoavs)
              {
                  CMSPageObjectAttributeValue newPoav = new CMSPageObjectAttributeValue();
                  newPoav.CMSAttributeID = poav.CMSAttributeID;
                  newPoav.CMSPageObjectID = newPageObject.ID;
                  newPoav.LCID = poav.LCID;
                  newPoav.Value = poav.Value;
                  newPoavs.Add(newPoav);
              }
              _db.CMSPageObjectAttributeValues.InsertAllOnSubmit(newPoavs);
          }
  
          _db.CMSPageObjects.InsertAllOnSubmit(newPageObjects);
          _db.SubmitChanges();
      }
  </code></pre>