WCF RIA 服务删除相关数据
假设我在实体“客户订单”之间有一对多关系。如果我删除客户,我还想删除所有相关订单。如果我在客户端尝试此操作:
foreach (Order order in cusomter.Orders)
{
Context.Orders.Remove(order);
}
Context.Customers.Remove(customer);
Context.SubmitChanges();
它首先在服务器上调用客户删除域操作,该操作由于数据库中的关系约束而失败。我怎样才能让它先删除订单?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
启用数据库中父子表关系的级联删除。
http://rudesyle.wordpress.com/2008/ 01/28/级联删除-in-sql-server/
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.