Another day with NHibernate, one more thing learnt…Ok, so if you”re going to use NH and you want it to play nice with the TransactionScope class introduced by .NET 2.0 and you”re using a provider which is capable on enlisting in an existing transaction (ex.: you”re connecting to SQL Server), then the only thing you need to remember is to call session.Flush before committing the trnasaction (ie, before calling the Complete method over the TransactionScope instance you”re using).
This is really important if you”ve got an entity which holds a collection of components. Fortunately for me, I”ve ended up finding this post by Oren which helped me putting it to work. You see, besides being an NH rookie, I was under the impression that if the session is associated with a transaction, then committing the transaction would automatically call Flush over that session”s instance. This seems to be true when you use an NH ITransaction, but it seems like it simply doesn”t work when you have component collections and you”re using TransactionScopes.