Created
September 15, 2011 20:59
-
-
Save johnathan-sewell/1220468 to your computer and use it in GitHub Desktop.
MVC controller accessing NHibernate SessionFactory from static variable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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