TransactionScope and rollback status

I am looking for a solution to a design problem. This will require a little explanation. I would post the code, but this woul will do it even longer.

I have a custom generic collection that I use to store business objects as needed. For convenience, call the BO business objects and the general GC collection. Inside the GC I have a private collection of those business objects that have been marked for deletion. Call this private PDC collection.

I can have an arbitrary amount of GC, each with its own PDC, at any time, plus other BOs that are not in any collection.

When I save the changes, I iterate over all the BO and GC and each save their changes. This happens in TransactionScope, so I roll back the database if something cannot be saved correctly.

When saving a GC, I have a problem with the state of my PDC. The GC first saves all updated BOs, then deletes the entries associated with the BOs in the PDC, and then clears the PDC of all the BOs . I am doing this so that the state of the GC correctly reflects the new state of the database.

Now suppose that the BO or GC could not be saved after successfully saving one or more of the GC. TransactionScope rolls back. Records deleted from the database were restored , but some / all of the PDCs were cleared and status information was lost .

So here is my quandry: how can I store PDC information until transactions occur, and then guarantee that the appriopriate collections are cleared?

TransactionScope does not have an event that I can catch to tell me when the changes occurred. There are potentially INR BOs and GCs affected by any particular transaction, so I cannot limit the transaction to processing one GC at a time.

Any suggestions?

+2
collections state transactionscope
source share
1 answer

TransactionStarted is raised by the transaction manager, and the transaction is completed by the transaction itself.

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

You can also check DNR TV show 113 and 114 .

+2
source share

All Articles