Working with a nHibernate session in an asp.net web application is a subject to many a blog post, forum question or overflowing stack. Having already made a contibution before, I am nevertheless going to add another go at it combining all I’ve met and trying to find a way to meet the objections to the different approaches.
The problemAccessing a database via nHibernate takes four steps. Create a sessionfactory.
Open a session.
Access data
Close the sessionCreating a sessionfactory is a very costly process, don’t do this to often. Opening a session is fast but results in an open connection to the database. Database connections are a costly external resource. Despite session pooling connections should be closed as soon as possible.
StrategiesTrying to balance to cost of creating a sessionfactory and the cost of an open database connection I’ve found several ways to manage the session. Do it yourself. Create the factory whenever the app needs data and fiddle on from there optimized to the occasion. Needless to say that’s not going to work unless you have a very simple app. Read more: CodeBetter
QR:
The problemAccessing a database via nHibernate takes four steps. Create a sessionfactory.
Open a session.
Access data
Close the sessionCreating a sessionfactory is a very costly process, don’t do this to often. Opening a session is fast but results in an open connection to the database. Database connections are a costly external resource. Despite session pooling connections should be closed as soon as possible.
StrategiesTrying to balance to cost of creating a sessionfactory and the cost of an open database connection I’ve found several ways to manage the session. Do it yourself. Create the factory whenever the app needs data and fiddle on from there optimized to the occasion. Needless to say that’s not going to work unless you have a very simple app. Read more: CodeBetter
QR:
0 comments:
Post a Comment