I'm confused by your assertion. I have used NHibernate in production applications using TransactionScope for transaction management. NHibernate properly enlisted in the ambient transaction. There was no need to call session.BeginTransaction()/tx.Commit() as well as new TransactionScope()/scope.Complete(). Just the latter was sufficient for proper transaction semantics. Are you using NHibernate 3.2? Can you provide a test case demonstrating the issue that you're seeing?
James On Apr 13, 4:56 am, John T <[email protected]> wrote: > Hi group, > > so I've discovered that NHibernate does not integrate at all well with the > Ambient Transaction. In fact, when using NHibernate within a > TransactionScope, one would be forgiven for thinking it doesn't integrate > at all. > > What should be the correct usage: > > public void Foo() > { > ISession session = null; // get session from wherever > > using (var transactionScope = new TransactionScope()) > { > session.Save(new PersistableObject { ArbitraryProperty = "a value" }); > transactionScope.Complete(); > } > > } > > is completely useless. What you actually have to do is: > > public void Foo() > { > ISession session = null; // get session from wherever > > using (var transactionScope = new TransactionScope()) > using (var transaction = session.BeginTransaction()) > { > session.Save(new PersistableObject { ArbitraryProperty = "a value" }); > transaction.Commit(); > transactionScope.Complete(); > } > > } > > So the fact that NHibernate has any integration with the Ambient > Transaction seems completely pointless. > > Now, I've looked (only cursory thus far) through the NHib src and have > noted a few areas of interest wrt to integrating with the Ambient > Transaction. But I want to ask if anyone has tried this already, and hit > any barriers along the way? > > Regards, > John.
