Thank you. This is the kind of response I hoped to get. :)

I neglected to dispose the session in my example, yes. However in the 
"real" code we utilise WCF for handling sessions (i.e. within the 
ReleaseInstance() event on the InstanceProvider, for those people who are 
familiar with WCF).

Point 2, 3 and 4 is what I would like to improve. I would like NHibernate 
to be better integrated with TransactionScope, so I don't have to create a 
new Session/explicitly start NH Transaction for every TransactionScope*. I 
want to help it get there, too. I am not just stamping my feet demanding 
"you" do it for me! :)

Regards,
J.

*Would I have to explicitly start a new NH Transaction for any n+1 
TransactionScopes I use for the same Session?

On Tuesday, April 17, 2012 1:05:27 PM UTC+1, Ramon Smits wrote:
>
>
> John,
>
> 1. Your example does not Dispose the session when you are finished. This 
> is something that must be done in *all* situations.
> 2. NHibernate more or less only works correctly when using the NHibernate 
> transaction AFAIK. That is the pattern NHibernate is using no matter what 
> environment.
> 3. The reason why you should not create a session out-side of the 
> transaction is becuase you could trigger modifications in the first level 
> cache which would then not be done within a transaction. Reads must also be 
> part of the same transaction.
> 4. AFAIK You cannot use 2nd level cache when using distributed 
> transactions.
>
>
> I agree that it is too bad that NHibernate does not have implicit 
> transactions when a Session is created within a TransactionScope but it 
> isn't really that hard to put this logic especially when you consider that 
> you should just always immediately begin an nhibernate transaction after 
> you have created the session.
>
> --
> Ramon
>

Reply via email to