TransactionScope和回滚对象状态 [英] TransactionScope and rolling back object state

查看:279
本文介绍了TransactionScope和回滚对象状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找解决设计问题的方法。这将需要一点解释。我会post代码,但是woul使这更长。

I'm looking for a solution to a design problem. This will take a bit of explaining. I would post code, but that woul make this even longer.

我有一个自定义通用集合,用于根据需要保存业务对象。为方便参考,请调用业务对象 BO 和通用集合 GC 。内部GC我有一个私人收集的那些业务对象已被标记为删除。致电此私人收藏 PDC

I have a custom generic collection I use to hold Business Objects as needed. For easy of reference, call the business objects BO and the generic collection GC. Inside GC I have a private collection of those business objects that have been flagged for deletion. Call this private collection PDC.

我可以有任意数量的GC,每个都有自己的PDC,在任何时候,加上不在任何集合的其他BO。

I can have an arbitrary number of GC's, each with their own PDC, at any one time, plus other BOs that aren't in any collection.

当我保存更改时,循环所有BO和GC,并让每个保存更改。这发生包裹在TransactionScope中,所以我回滚数据库更改,如果任何无法正确保存。

When I save changes I loop over all BO and GC and have each one save their changes. This happens wrapped in a TransactionScope so I rollback database changes if anything fails to save properly.

当GC保存时,我的PDC的状态有问题。 GC首先保存所有具有更新的BO,然后删除与PDC中的BO相关联的记录,然后清除所有BO的PDC 。我这样做所以GC的状态正确地反映了数据库的新状态。

When a GC saves I have a problem with the state of its PDC. The GC first saves all BOs with updates, then deletes records associated with the BOs in the PDC, then clears the PDC of all BOs. I do this so the state of the GC correctly reflects the new state of the database.

现在假设在一个或多个GC成功保存后,BO或GC无法保存。 TransactionScope执行回滚。从数据库中删除的记录已恢复,但部分/全部PDC已清除,状态信息丢失

Now suppose a BO or GC fails to save after one or more of the GC has successsfully saved . The TransactionScope performs a rollback. The records deleted from the database are restored, but the some/all of the PDC's have been cleared and that state information lost.

是我的quandry:我如何保持PDC信息,直到提交发生后,然后保证专用集合被清除?

So here is my quandry: How do I keep the PDC information around until after the commit has occured, then guarantee the appriopriate collections are cleared?

TransactionScope没有事件,我可以捕获,让我知道当更改已提交。有潜在的MANY BO和GC受任何给定事务的影响,因此我不能限制事务一次处理一个GC。

TransactionScope has no event I can catch to let me know when it the changes have been committed. There are potentially MANY BOs and GC affected by any given transaction, so I can't restrict the transaction to handle one GC at a time.

任何建议?

推荐答案

TransactionStarted是由交易经理和事务本身的TransactionCompleted。

The TransactionStarted is raised by the transaction manager, and the TransactionCompleted by the transaction itself.

您可能希望GC实现 IEnlistmentNotification ;有一个例子可以帮助你。

You may want the GC to implement IEnlistmentNotification; there is an example that may help you.

您还可以检查 DNR电视节目113 114

这篇关于TransactionScope和回滚对象状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆