1

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

4

2 回答 2

1

我没有尝试过,但你可以考虑以下。首先,获取ChangeSetusing DataContext.ChangeSet. 然后,运行对您的新实例的ChangeSet.Deletes调用。冲洗重复和。Table<T>.DeleteOnSubmitDataContextChangeSet.UpdatesChangeSet.Inserts

祝你好运。

于 2010-02-05T22:03:44.037 回答
0

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.

于 2010-02-05T21:57:40.713 回答