日期:2014-05-17 浏览次数:20425 次
[NHibernateSession]
public ActionResult SaveNewOrder(Order order)
{
......
return RedirectToAction("Index");
}
[AttributeUsageAttribute(AttributeTargets.Method, Inherited = false, AllowMultiple = false)]
public class NHibernateSessionAttribute : FilterAttribute, IActionFilter
{
public NHibernateSessionAttribute() : base()
{
}
public void OnActionExecuting(ActionExecutingContext filterContext)
{
var session = SessionProvider.GetNewSession();
CurrentSessionContext.Bind(session);
}
public void OnActionExecuted(ActionExecutedContext filterContext)
{
CurrentSessionContext.Unbind(SessionProvider.GetSessionFactory()).Close();
}
}