Linq to Sql - DeleteOnSubmit() - no errors - just not working...

Last post 10-08-2008 2:06 PM by chrisaswain. 1 replies.

Sort Posts:

  • Linq to Sql - DeleteOnSubmit() - no errors - just not working...

    10-08-2008, 12:25 PM
    • Member
      7 point Member
    • chrisaswain
    • Member since 12-07-2006, 10:31 AM
    • Phoenix, AZ
    • Posts 13

    I have a Dynamic Data page showing a ListView of items, each with a LinkButton to delete [CommandName=Delete].  I'm capturing the ItemDeleting event and cancelling it [e.Cancel = true], then doing a custom delete.  First I create a new instance of my datacontext, then I use the deleted row's PK to get a new instance of the Entity to delete.  Finally I pass the new entity to the DeleteOnSubmit(entity) function [myContext.myTable.DeleteOnSubmit(myEntity)], and SubmitChanges().  When I run the code, there are no errors, but the record does not get deleted.  It's as if the code never ran.  Here is my actual code:

        protected void AdHocReportsListView_ItemDeleting(object sender, ListViewDeleteEventArgs e)
        {
            if (e.ItemIndex > -1)
            {
                EntitySet rpts = ((DataBoundControl)sender).DataSource as EntitySet;
                if (rpts != null)
                {
                    AdHocReport deletedRpt = rpts[e.ItemIndex];
                    using (MyDataContext context = new MyDataContext())
                    {
                        AdHocReport rpt = context.AdHocReports.Single(item => item.AdHocReportId == deletedRpt.AdHocReportId);
                        context.AdHocReports.DeleteOnSubmit(rpt);
                        context.SubmitChanges();
                    }
                }
            }
            e.Cancel = true;
        }
    
     
  • Re: Linq to Sql - DeleteOnSubmit() - no errors - just not working...

    10-08-2008, 2:06 PM
    Answer
    • Member
      7 point Member
    • chrisaswain
    • Member since 12-07-2006, 10:31 AM
    • Phoenix, AZ
    • Posts 13

    I fixed this.  Apparently I had implemented the partial method DeleteAdHocReport and was doing nothing in it.  Once I commented out this implementation, everything worked fine.  I should have known better.  But you live and learn, I guess. 

Page 1 of 1 (2 items)