title: The relationship could not be changed because one or more of the foreign-key properties is non-nullable
body: <p>I am getting this error when I GetById() on an entity and then set the collection of child entities to my new list which comes from the MVC view.</p>
  
  <blockquote>
    <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>
  </blockquote>
  
  <p>I don't quite understand this line:</p>
  
  <blockquote>
    <p>The relationship could not be changed
    because one or more of the foreign-key
    properties is non-nullable.</p>
  </blockquote>
  
  <p>Why would I change the relationship between 2 entities? It should remain the same throughout the lifetime of the whole application.</p>
  
  <p>The code the exception occurs on is simple assigning modified child classes in a collection to the existing parent class.  This would hopefully cater for removal of child classes, addition of new ones and modifications.  I would have thought Entity Framework handles this.</p>
  
  <p>The lines of code can be distilled to:</p>
  
  <pre><code>var thisParent = _repo.GetById(1);
  thisParent.ChildItems = modifiedParent.ChildItems();
  _repo.Save();
  </code></pre>