Say I have a one-to-many relation between entities Customer-Order. If I delete a Customer I also want to delete all related Order’s. If I try this on the client side:
foreach (Order order in cusomter.Orders)
{
Context.Orders.Remove(order);
}
Context.Customers.Remove(customer);
Context.SubmitChanges();
It calls the Customer delete domain operation on the server first, which fails because of a relational constraint in the database. How can I get it to delete the Orders first?
SubmitChanges before removing the customer, and it will fix your issue.
EDIT: You’ll have to submitchanges twice.