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:
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.
Marked as answer by chrisaswain on Oct 08, 2008 06:06 PM
chrisaswain
Member
8 Points
15 Posts
Linq to Sql - DeleteOnSubmit() - no errors - just not working...
Oct 08, 2008 04:25 PM|LINK
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; }chrisaswain
Member
8 Points
15 Posts
Re: Linq to Sql - DeleteOnSubmit() - no errors - just not working...
Oct 08, 2008 06:06 PM|LINK
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.