creating sessions is cheap. so opening/disposing of a session in the begin/end request isn't the issue. The issue is when to open/close the db connection. this is where the cost lies. using an ActionFilter (Filter in MR) you can begin a transaction before the action is executed and commit/rollback the transaction after the action.
remember NH Session != Db Connection. it manages connection(s), but it's not 1:1. On Jan 7, 1:30 am, Martin <[email protected]> wrote: > If you're initializing the NHib stuff in Application_BeginRequest, one > additional optimization you can make is to only do so for non-static > requests: > > This is the approach used in the awesome Who Can Help Me sample MVC > app: > > http://whocanhelpme.codeplex.com/SourceControl/changeset/view/53686#8... > > protected void Application_BeginRequest(object sender, > EventArgs e) > { > // Only initialise the NHibernate Sessions for a non > static, i.e. Controller Action request > if (!this.Request.IsStaticFile()) > { > NHibernateInitializer.Instance().Initialize > (this.InitialiseNHibernateSessions); > } > } > > Though I don't think this is as efficient as the attribute per usage > approach. > > On Jan 6, 5:28 pm, Jason Meckley <[email protected]> wrote: > > > opening a session doesn't mean you will open a database connection. > > once you call begin transaction or a CRUD operation it will open the > > connection if it doesn't exist. > > > I used to mange my session and transactions all within an http module. > > whether I needed an open connection or not. however i found that > > managing the session scope at the module level and transactions with > > an ActionFilter keeps the session-per-request scope while efficiently > > using transactions. > > > On Jan 6, 6:57 pm, José F. Romaniello <[email protected]> wrote: > > > > Am I wrong if I say that this code should NOT open a connection? > > > > NHibernate.ISession ormSession = GetSessionFactory().OpenSession(); > > > > NHibernate.Context.CurrentSessionContext.Bind(ormSession);
-- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
