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

Creating a Transaction ASP.NET MVC action filter

We can extend the concepts of the previous recipe to NHibernate transactions as well. In this recipe, I'll show you how to create an action filter to manage our NHibernate sessions and transactions.

Getting ready

Complete the previous recipe, Creating a Session ASP.NET MVC action filter.

How to do it...

  1. Add the NeedsPersistenceAttribute class as shown on the following lines of code:
     [AttributeUsage(AttributeTargets.Method, AllowMultiple=true)] public class NeedsPersistenceAttribute : NHibernateSessionAttribute { protected ISession session { get { return sessionFactory.GetCurrentSession(); } } public override void OnActionExecuting( ActionExecutingContext filterContext) { base.OnActionExecuting(filterContext); ...

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