Hi,
This is an interesting one, as we are using NHibernate (SQL Server 2005) with the ASP.Net 2 Membership API, which is calling a different db. When we use transaction scope it works with NH, with the following provisos:
Make sure the first call with the TransactionScope to NH managed objects opens a new session. So, close your session when getting the transactionscope. We made a TransactionScopeWorker object which did this for us, ensuring we had a new session to play with at the start of every transaction. Makes good sense as well, flusing out any outstanding work.
Next, do all your calls. We had problems with just leaving the changes to objects and not explicitly calling a Save() (with flush) before the scope.Complete() call. For some reason the NH managed transaction does not get it's commit called automatically by the TransactionScope object.
So, as long as you start with a new session and explicitly flush after each unit of work (not necessary to close session) you can combine NH with other DB calls.
One last thing to note is that MS DTC may need to be installed on your SQL Server and Dev Boxes. The System.Transactions is based on some old COM+ Enterprise Services stuff that required us to use MSDTC to manage multiple db connections.
This sort of stuff is bound to get easier, took us a while to get this right.
|