R – Deleting data in Silverlight 3 with .NET RIA Data Services

entity-frameworksilverlight-3.0wcf-ria-services

We're trying to play around with RIA Services. I can't seem to figure out how to delete a record. Here's the code I'm trying to use.

   SomeDomainContext _SomeDomainContext = (SomeDomainContext)(productDataSource.DomainContext);
    Product luckyProduct = (Product)(TheDataGrid.SelectedItem);

    _SomeDomainContext.Products.Remove(luckyProduct);

    productDataSource.SubmitChanges();

The removing the object from the Entity part works fine, but it doesn't seem to do anything to the DB. Am I using the objects like I'm supposed to, or is there a different way of saving things?

Best Answer

The error system is a little finicky. Try this o get the error if there is one and that will give you an idea. My problem was dependencies to other tables needing deletion first before the object could be. Ex: Tasks deleted before deleting the Ticket.

System.Windows.Ria.Data.SubmitOperation op = productDataSource.SubmitChanges();
op.Completed += new EventHandler(op_Completed);

void TicketsLoaded_Completed(object sender, EventArgs e) {
   System.Windows.Ria.Data.SubmitOperation op = (System.Windows.Ria.Data.SubmitOperation)sender;
   if (op.Error != null) {
      ErrorWindow view = new ErrorWindow(op.Error);
      view.Show();
   }
}