Hi and guys,

I did some more tests and what i realize is that NH don't create a new
transaction 'b' at sub scope 's' as expected, it's using the same
transaction 'a' of the outer  scope and so, all save actions are
rolledback at the end. Am i missing something?!
Maybe the code above don't show what talking about... sorry my
mistakes...

ISession session = factory.OpenSession();

using (TransactionScope s = new TransactionScope ())
{

    // transaction 'a' is active here
    session.Save(obj1);

    using (TransactionScope t = new TransactionScope
(TransactionScopeOption.RequiresNew))
    {
        // transaction 'b' is active here
        session.Save(obj2);

        t.Complete ();
    }

    // transaction 'a' is active here

    using (TransactionScope u = new TransactionScope ())
    {
        // transaction 'a' is active here
        session.SaveOrUpdate(obj1);

    } // 'a' rolls back here,

      //the transaction from 's' is put into Current.
     // transaction 'a' is current, but aborted here
    s.Complete ();

}  // 'a' is already aborted, so is just removed at this point

At this point obj1 and obj2 wasn't saved neither updated at the
database.

Following the expectations based on TransactionScope behavior obj2
should be saved and obj1 should be rolledback (save and update), but
in this case above, obj2 is not being saved in a new transaction.

Thanks again!



On 20 jun, 00:23, Marcus Rehm <[email protected]> wrote:
> Hi,
>
> I have a question aboute TransactionScope.
> If i understood correctly the ISession instance can only have one
> Transaction, so how NH handle the following code when RequiresNew is
> passed to the sub scope 't' and transaction 'a' is rolledback in sub
> scope 'u'?
>
> using (TransactionScope s = new TransactionScope ())
> {
>
>     // transaction 'a' is active here
>
>     using (TransactionScope t = new TransactionScope
> (TransactionScopeOption.RequiresNew))
>     {
>         // transaction 'b' is active here
>
>         t.Complete ();
>     }
>
>     // transaction 'a' is active here
>
>     using (TransactionScope u = new TransactionScope ())
>     {
>         // transaction 'a' is active here
>     } // 'a' rolls back here,
>
>       //the transaction from 's' is put into Current.
>      // transaction 'a' is current, but aborted here
>     s.Complete ();
>
> }  // 'a' is already aborted, so is just removed at this point
>
> Thanks in Advance!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to