Note that there are some explanatory texts on larger screens.

plurals
  1. PONested Transactions in .NET
    primarykey
    data
    text
    <p>How can I perform the equivalent of this? <a href="https://stackoverflow.com/questions/2741988/nested-child-transactionscope-rollback">My understanding is that this is impossible with TransactionScopes</a> but I'd like to accomplish the equivalent in some other way:</p> <p>Business Logic class:</p> <pre><code>public bool Bar() { try { using (var tsWork = new TransactionScope()) { ComplicatedDataImportCode(somedata); FlagRecordInDatabaseAsImported(); // this is the same record that's modified in the catch tsWork.Complete(); return true; } catch (DuplicateDataException err) { // if we got here, the above transaction should have rolled back, // so take that same record in the database and update it to "Duplicate". FlagSameRecordInDatabaseAsDuplicate(err.Message); } return false; } </code></pre> <p>Now this works fine, until I encapsulate all of this inside of a transaction (perhaps an integration test that I want to rollback after performing asserts).</p> <p>Simple test to prove my point:</p> <pre><code>public void CanTest() { // Arrange var foo = new Foo(); using (var ts = new TransactionScope()) { // Act var success = foo.Bar(); // Assert if (success) { Assert.That(SomethingThatTestsThatTheDataWasImported); } else { Assert.That(SomethingThatTestsThatTheRecordWasMarkedAsDuplicate); } // Now that we have been able to perform our Asserts, rollback. } } </code></pre> <p>Ultimately, the code in <code>Foo.Bar()</code> can be modified to accommodate a solution however, the code in <code>ComplicatedDataImportCode()</code> cannot be modified for this solution, and is consequently what I really need to make sure I properly rollback in the failure scenario.</p> <p>Again, I understand that TransactionScopes cannot be used to do this, according to the post that I referenced at the beginning of this question. I used TransactionScopes here to indicate what I wanted to do, and am looking for the best alternative way to implement this functionality.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload