title: Deleting element from an observableArray
body: <p>I have an ASP.NET MVC app that uses durandal, knockout.js, and breeze on the client.  I have an issue that I'm encountering repeatedly, and yet I haven't found any mention of it anywhere.  Not sure if I've gotten myself into a unique situation, or if I'm just not searching the right way.</p>
  
  <p>I need to know how to delete a Breeze entity from an observableArray so that the commit succeeds (see Option A below) and the UI reflects the change (see Option B below).</p>
  
  <p>I have the following models (abbreviated):</p>
  
  <pre><code>public class Donor
  {
      [Required]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      public virtual IList&lt;Contact&gt; Contacts { get; set; }
  }
  
  public class Contact
  {
      [Required]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int Id { get; set; }
  
      [ForeignKey("Donor")]
      public int? DonorId { get; set; }
      public virutal Donor Donor { get; set; }
  }
  </code></pre>
  
  <p>I'm trying to delete a Contact from my Donor.  I am having difficulty getting the flow right between Breeze and Knockout so that the item is both removed from the <code>observableArray</code> (with a notification) and also able to be deleted through Breeze.</p>
  
  <p>Here is what I have tried (javascript):</p>
  
  <p><strong>Option A</strong>:</p>
  
  <pre><code>function deleteContact(contact){
      viewModel.donor().contacts.remove(contact);
      contact.entityAspect.setDeleted();
      viewModel.uow.commit();
  }
  </code></pre>
  
  <p>When I use this approach, I get the following error from Breeze.WebApi:</p>
  
  <blockquote>
    <p>Int32Converter cannot convert from System.Int64</p>
  </blockquote>
  
  <p>I have looked through the stack, and examined the Breeze source code (though I haven't yet configured a solution to step through it), and the error is coming from Breeze.WebApi.EFContextProvider::RestoreOriginal, where it is restoring original property values to the object.  I don't know why it thinks my value is an Int64, but I was not able to find a good work-around, so I tried...</p>
  
  <p><strong>Option B</strong>:</p>
  
  <pre><code>function deleteContact(contact){
      contact.entityAspect.setDeleted();
      viewModel.uow.commit();
  }
  </code></pre>
  
  <p>This approach allows me to successfully save the delete (because the item has not been removed from the collection manually, and therefore, doesn't have any "original values").  However, the issue here is that <code>setDeleted</code> effectively removes the item from the observableArray <strong>without notifying</strong> my knockout bindings that the array has changed.  So the item has been removed and deleted, but my UI still shows the item.  Future attempts to call <code>donor().contacts.remove(contact)</code> are futile, because the observableArray no longer has the item.</p>