NHibernate Session Management Advice

Posted by Hugusta on Stack Overflow See other posts from Stack Overflow or by Hugusta
Published on 2010-12-29T00:22:11Z Indexed on 2010/12/29 1:54 UTC
Read the original article Hit count: 587

I need some advice on NHibernate Session Management for a C# WinForms application.

I am currently porting an application to use NHibernate. I am also employing a UnitOfWork pattern as described in the link below;

http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx

My question relates to Sessions.

  1. Can you only have one session running per thread at all times?

  2. I have a scenario in which a Session (UnitOfWork) may be open for a form shown by the application but the user opens another form (i.e. Tools - Options) which I would like to have its own UnitOfWork. Clearly in this instance it would make more sense to open another Session for the "Tools - Options" form and not use the currently open session for the underlying form.

  3. Can we have a Dictionary of Sessions on the one thread?

Any advice on session management is appreciated.

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms