O'Reilly logo

NHibernate 4.x Cookbook - Second Edition by Jason Dentler, Alexander Zaytsev, Gunnar Liljas

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

Save entities to the database

Clearly we have saved entities to the database in many of the previous recipes, but it's time to dig a bit deeper into how that actually works. This recipe will explore different ways of saving and what happens behind the scenes.

Getting ready

  1. Create a new Windows forms project named SessionRecipes, in Visual Studio.
  2. Add a reference to NHibernate using NuGet Packet Manager Console:
    Install-Package NHibernate -project SessionRecipes
    
  3. Also add a reference to NH4CookbookHelpers:
    Install-Package NH4CookbookHelpers -project SessionRecipes
    
  4. Remove the class Form1.cs from the project.
  5. Add using NH4CookbookHelpers; to the top of Program.cs.
  6. Edit Program.cs so that the last line in Main reads:
    Application.Run(new WindowsFormsRunner()); ...

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