title: The EntityCollection has already been initialized
body: <p>I'm trying to update an existing entity</p>
  
  <pre><code>private void UpdateEfItem(MamConfiguration_V1 itemFromDb, MamConfiguration_V1 item)
  {
      itemFromDb.UpdatedDate = DateTime.Now;
      itemFromDb.Description = item.Description;
  
  
     //references
     itemFromDb.MamConfigurationToBrowser_V1 = item.MamConfigurationToBrowser_V1;
     itemFromDb.MamConfigurationToGroups_V1 = item.MamConfigurationToGroups_V1;
  }
  </code></pre>
  
  <p>I get the following error, when assigning Ui-Item to Ef-item:</p>
  
  <pre><code>itemFromDb.MamConfigurationToBrowser_V1 = item.MamConfigurationToBrowser_V1;
  </code></pre>
  
  <blockquote>
    <p>The <code>EntityCollection</code> has already been initialized. The
    <code>InitializeRelatedCollection</code> method should only be called to initialize
    a new <code>EntityCollection</code> during deserialization of an object graph.</p>
  </blockquote>
  
  <p><strong>Update:</strong></p>
  
  <p>I have tried @Gert's way:</p>
  
  <pre><code>    private void UpdateEfItem(MamConfiguration_V1 itemFromDb, MamConfiguration_V1 item)
      {
          itemFromDb.UpdatedDate = DateTime.Now;
  
          itemFromDb.Description = item.Description;
  
          itemFromDb.StatusId = item.StatusId;
  
          itemFromDb.Name = item.Name;
  
          itemFromDb.NumericTraffic = item.NumericTraffic;
  
          itemFromDb.PercentageTraffic = item.PercentageTraffic;
  
          itemFromDb.Type = item.NumericTraffic;
  
  
  
          itemFromDb.MamConfigurationToBrowser_V1.Clear();
  
          for (int i = 0; i &lt; item.MamConfigurationToBrowser_V1.Count; i++)
          {
              var elementToAdd = item.MamConfigurationToBrowser_V1.ElementAt(i);
  
              elementToAdd.Browser = mMaMDBEntities.Browsers.Single(browserItem =&gt; browserItem.BrowserID == elementToAdd.BrowserID);
  
              elementToAdd.MamConfiguration_V1 = itemFromDb;
  
              itemFromDb.MamConfigurationToBrowser_V1.Add(elementToAdd);
          }
  </code></pre>
  
  <p>and get the following error:</p>
  
  <p>only when adding the <code>clear</code> and <code>add</code> commands</p>
  
  <p>The operation failed: The relationship could not be changed because one or more of the foreign-key properties is non-nullable. When a change is made to a relationship, the related foreign-key property is set to a null value. If the foreign-key does not support null values, a new relationship must be defined, the foreign-key property must be assigned another non-null value, or the unrelated object must be deleted.</p>