title: Entity Framework proper way to replace collection in one to many
body: <p>Suppose a customer has many phone numbers and a phone number has only one customer.</p>
  
  <pre><code>public class PhoneNumber : IValueObject {
    public string Number {get; set;}
    public string Type {get; set;}
  }
  
  public class Customer : IEntity {
     public ICollection&lt;PhoneNumber&gt; phones {get; private set;} //ew at no encapsulated collection support
     public void SetPhones(params PhoneNumber[] phones) {
         this.phones.Clear();
         this.phones.AddRange(phones);
     }
  }
  </code></pre>
  
  <p>If I do an EF mapping like this and run it, every time I set phone numbers it will create new PhoneNumbers but not delete the old ones. There are no other entities referencing phone numbers, I don't even expose it on my dbcontext, is there a way to tell EF that <code>Customer</code> owns <code>PhoneNumbers</code> completely and therefore if phone numbers were removed from the collection they should be deleted?</p>
  
  <p><img src="https://content.screencast.com/users/togakangaroo/folders/Jing/media/12499b0b-0185-453c-b24f-8ab7ba292112/2015-05-08_0944.png" alt="proof"></p>
  
  <p>I realize that there's a dozen ways to hack around this problem, but this isn't a weird edge case, what's the "right" way to handle this.</p>