Removing ado.net entity strings

I may be completely blind and stupid, but I cannot find any method created by the ADO.NET Entity Data Model that somehow removes rows from my table. I did not want to create a custom query. So how do I do this? Please, help.

I do not have the DeleteOnSubmit method ... I don’t know why. This is the code I wanted to use.

var deleteOrderDetails = from details in db.OrderDetails where details.OrderID == 11000 select details; foreach (var detail in deleteOrderDetails) { db.OrderDetails.DeleteOnSubmit(detail); } db.SubmitChanges(); 
+6
c # asp.net-mvc
source share
2 answers

A couple of changes are required:

 db.DeleteObject(detail); 

and

 db.SaveChanges(); 

Kindness,

Dan

PS: Did you use Linq for SQL and then change to Entity Framework?

+10
source share

Here is another way (thanks this answer )

I assume that you have an Orders table, and OrderDetails is linked to it through OrderID .

 var order = db.Orders.FirstOrDefault(o=> o.OrderID == 11000); if(order != null) { order.OrderDetails.Clear(); db.SaveChanges(); } 

This should remove all order details associated with this order.

Edit: fixed code

+5
source share

All Articles