开发者

WCF RIA Services deleting related data

开发者 https://www.devze.com 2023-03-01 06:16 出处:网络
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:

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?


Enable cascading deletes on the relationship between the parent and child table in the database.

http://rudesyle.wordpress.com/2008/01/28/cascading-deletes-in-sql-server/


SubmitChanges before removing the customer, and it will fix your issue.

EDIT: You'll have to submitchanges twice.

0

精彩评论

暂无评论...
验证码 换一张
取 消