title: Can EF automatically delete data that is orphaned, where the parent is not deleted?
body: <p>For an application using Code First EF 5 beta I have:</p>
  
  <pre><code>public class ParentObject
  {
      public int Id {get; set;}
      public virtual List&lt;ChildObject&gt; ChildObjects {get; set;}
      //Other members
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>public class ChildObject
  {
      public int Id {get; set;}
      public int ParentObjectId {get; set;}
      //Other members
  }
  </code></pre>
  
  <p>The relevant CRUD operations are performed by repositories, where necessary.</p>
  
  <p>In</p>
  
  <pre><code>OnModelCreating(DbModelBuilder modelBuilder)
  </code></pre>
  
  <p>I have set them up:</p>
  
  <pre><code>modelBuilder.Entity&lt;ParentObject&gt;().HasMany(p =&gt; p.ChildObjects)
              .WithOptional()
              .HasForeignKey(c =&gt; c.ParentObjectId)
              .WillCascadeOnDelete();
  </code></pre>
  
  <p>So if a <code>ParentObject</code> is deleted, its ChildObjects are too.</p>
  
  <p>However, if I run:</p>
  
  <pre><code>parentObject.ChildObjects.Clear();
  _parentObjectRepository.SaveChanges(); //this repository uses the context
  </code></pre>
  
  <p>I get the exception:</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>This makes sense as the definition of the entities includes the foreign key constraint which is being broken.</p>
  
  <p>Can I configure the entity to "clear itself up" when it gets orphaned or must I manually remove these <code>ChildObject</code>s from the context (in this case using a ChildObjectRepository).</p>