I am using a .NET transaction scope and running the following to
verify transaction commits/rollbacks
Using 2.1 nhibernate talking to SQL server db.

var b1 = new Person {Email = "[email protected]", Username = "art"};
using (var session = NHibernateSession.CurrentFor("MyDatabase"))
{
      session.Save(b1);
      session.Flush();
  }
//Writes b1 away to database

using (var tx = new TransactionScope())
{
     using (var session = NHibernateSession.CurrentFor("MyDatabase"))
     {
          var b2 = (Person)session.Load(typeof(Person), b1.Id);
          b2.Username = "art1234";
          session.Flush();
      }
       tx.Complete();
}

using (var session = NHibernateSession.CurrentFor("MyDatabase"))
{
     var b3 = (Person)session.Load(typeof(Person), b1.Id);
     Assert.IsTrue(b3.Username == "art");
}


If I leave the session.Flush() uncommented the transaction commits
even if I have the tx.Complete() commented out - I was expecting the
transaction scope to decide whether to commit those changes. If I
comment out session.Flush() and don't set tx.Complete() then the
transaction rolls back as expected.

My guess is that session.Flush creates its own implicit transaction
and commits it and ignores the current .NET transaction scope.

Thanks

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