LINQ 上下文 SubmitChanges

发布于 2024-08-20 14:48:19 字数 254 浏览 1 评论 0原文

关于 SubmitChanges 顺序(插入、更新、删除),有没有办法更改该顺序?我需要先执行删除,然后执行任何更新,然后执行任何新插入。我有一个数据网格,用户可以在其中执行所有添加、更改和更新并提交。由于每个网格行必须在其中选择一个唯一的项目(通过下拉列表),因此用户可以删除该行,然后尝试在新行中使用已删除的下拉项目,然后尝试更新所有更改并拥有更新失败(因为用户想要删除的项目实际上仍然存在于数据库中,因为提交首先执行插入)。是否有一个设置可以控制自动更新顺序,或者我必须自己手动进行更新?

Regarding the SubmitChanges order (Insert, Update, Delete), is there a way to change that order? I need to have the Deletes executed first, any updates, then any new inserts. I have a datagrid where the user can do all add, changes and updates and submit. Since each grid row must have a unique item chosen in it (via a dropdown), it's possible for the the user to delete the row, then try to utilize the deleted dropdown item in a new row, then try to update all changes and have the update fail (since the item the user wants to delete actually still exists in the database because the submit is doing the inserts first). Is there a setting where I can control the automatic update order or do I have to manually do the updates myself?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷鸟归林 2024-08-27 14:48:19

我没有尝试过,但你可以考虑以下方法。首先,使用 DataContext.ChangeSet。然后,在 DataContext 的新实例上运行调用 Table.DeleteOnSubmitChangeSet.Deletes。重复冲洗 ChangeSet.UpdatesChangeSet.Inserts

祝你好运。

I have not tried this, but you could consider the following. First, get the ChangeSet using DataContext.ChangeSet. Then, run through the ChangeSet.Deletes calling Table<T>.DeleteOnSubmit on a new instance of your DataContext. Rinse repeat for the ChangeSet.Updates and the ChangeSet.Inserts.

Good luck.

许仙没带伞 2024-08-27 14:48:19

我不相信这是可能做到的。您必须按照您想要的顺序处理更改,并在每次插入、更新或删除后调用 SubmitChanges()。如果您希望整个事务都在事务范围内,请使用 TransactionScope 对象。

I don't believe it's possible to do this. You would have to process the changes in the order you want, and call SubmitChanges() after each insert, update or delete. If you want the whole thing within the scope of a transaction, use the TransactionScope object.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文