O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Setting up session per web request

Because of its simplicity, the most common pattern used in web applications for managing NHibernate sessions is session-per-request. In this recipe, I'll show you how to set up the session-per-request pattern using NHibernate's contextual sessions feature.

Getting ready

  1. Create a new ASP.NET Web Forms or ASP.NET MVC application.
  2. Add references to NHibernate.dll, NHibernate.ByteCode.Castle.dll, log4net.dll, and our Eg.Core model and mappings project from Chapter 1.
  3. In the web.config file, set up the NHibernate and log4net configuration sections. Refer to the Configuring NHibernate with App.config recipes in Chapter 2.

How to do it...

  1. In the hibernate-configuration section of web.config, add the current_session_context_class ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required