title: Entity Framework Code First deleting one to zero/one child from parent
body: <p>I have created a simple one to zero/one relationship inside of code first.  The code below works in that I can have a Person instance and optionally have an Account and its modeled fine in the database.</p>
  
  <pre><code>public class Person
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public virtual Account Account { get; set; }
  }
  
  public class Account
  {
      public int Id { get; set; }
      public string Location { get; set; }
      public virtual Person Owner { get; set; }
  }
  //Mapping
  modelBuilder.Entity&lt;Person&gt;().HasOptional(x =&gt; x.Account).WithRequired(x =&gt; x.Owner);
  </code></pre>
  
  <p>What I would like to do is to be able to delete the optional child from the parent.  I would expect this to work.</p>
  
  <pre><code>using (Context ctx = new Context())
  {
      var personToDeleteFrom = ctx.Persons.Single(x =&gt; x.Id == &lt;personid&gt;);
      personToDeleteFrom.Account = null;
      ctx.SaveChanges();
  }
  </code></pre>
  
  <p>However, the child object of the relationship is simply left in the database. Is there a way to make this work?  If not, what is the best practice for handling this type of relationship?</p>