How can I do more than one level of cascading deletes in Linq?

Posted by Gary McGill on Stack Overflow See other posts from Stack Overflow or by Gary McGill
Published on 2010-03-23T23:30:37Z Indexed on 2010/03/23 23:33 UTC
Read the original article Hit count: 239

Filed under:
|

If I have a Customers table linked to an Orders table, and I want to delete a customer and its corresponding orders, then I can do:

dataContext.Orders.DeleteAllOnSubmit(customer.Orders);
dataContext.Customers.DeleteOnSubmit(customer);

...which is great. However, what if I also have an OrderItems table, and I want to delete the order items for each of the orders deleted?

I can see how I could use DeleteAllOnSubmit to cause the deletion of all the order items for a single order, but how can I do it for all the orders?

© Stack Overflow or respective owner

Related posts about LINQ

Related posts about linq-to-sql