Hi, I'm troubled with finding the most correct use of TransactionScope in combination with NHibernate and it's session. There are numerous source that all tell the same thing but with subtle differences. One thing I'm absolutely sure of is that each query, even a select query, must be in a transaction. This transaction can be a NHibernate transaction or/and a System.Transactions.Transaction, and here all sources differ, is it 'or' or is it 'and'.
So if I start with the first source the NHibernate 3.0 Cookbook by Jason Dentler it tells me to always use an NHibernate transaction in a TransactionScope. "*Remember that NHibernate requires an NHibernate transaction when interacting with the database. TransactionScope is not a substitute.*" Jason has introduced a Transact method that encapsulates each action the repository with a NHibernate Transaction if the session doesn't already have one. You can find the implementation here: https://www.packtpub.com/article/nhibernate-3-working-with-data-access-layer . The second source is NHProf, this also says that I have to use transaction with each action. But it gives me the choice between NHibernate transaction or Transactionscope. It also behaves strange when I use both, it doesn't detect the transactions very well. "*I strongly suggest that you use code similar to that shown above (or use another approach to transactions, such as TransactionScope, or Castle's Automatic Transaction Management) in order to handle transactions correctly*." ( http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions) The first source tells me to use both, the second tells me to use only one. Then there is a third source, a blogpost by Davy Brion, that says to use both but for a different reason namely leaking connections. In fact if I use the code that is in Jason's book I comply with what Davy says. ( http://davybrion.com/blog/2010/05/avoiding-leaking-connections-with-nhibernate-and-transactionscope/ ) The trouble starts when I want to use the same code on a Sql Server database and an Oracle database. Oracle does something different with it's transactions, but don't want to go in to much detail for now. I'm using NHibernate 3.1.0 GA and the repository pattern from Jason's book with the Transact method. But I added an extra check that also checks for the existence of a TransactionScope, so that I comply with what I think NHProf is telling me and solves a lot, not all, of the troubles I have with Oracle. So my question is what's the deal with Transactionscope? And what is the best implementation? Jochen Jonckheere -- 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.
