views:

256

answers:

1

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.

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.

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.

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.

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.

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.

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 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.

Any suggestions?

+1  A: 

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

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

You may also want to check DNR TV show 113 and 114.

Wilhelm
This looks perfect. Thanks for the links as well. This should solve my problem
RB Davidson