Skip to content

Instantly share code, notes, and snippets.

@johnathan-sewell
Created September 15, 2011 20:59
Show Gist options
  • Save johnathan-sewell/1220468 to your computer and use it in GitHub Desktop.
Save johnathan-sewell/1220468 to your computer and use it in GitHub Desktop.
MVC controller accessing NHibernate SessionFactory from static variable
public class HomeController : Controller
{
public ActionResult Index()
{
//Get static SessionFactory defined in Global.asax
var session = MvcApplication.SessionFactory.GetCurrentSession();
using (ITransaction transaction = session.BeginTransaction())
{
var word = new Word
{
Text = "Abracadabra"
};
session.Save(word);
transaction.Commit();
ViewBag.Message = "Word saved: " + word.Text;
}
return View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment