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
Create a new Windows forms project named
SessionRecipes, in Visual Studio.Add a reference to
NHibernateusing NuGet Packet Manager Console:Install-Package NHibernate -project SessionRecipesAlso add a reference to
NH4CookbookHelpers:Install-Package NH4CookbookHelpers -project SessionRecipesRemove the class
Form1.csfrom the project.Add
using NH4CookbookHelpers;to the top ofProgram.cs.Edit
Program.csso that the last line inMainreads:Application.Run(new WindowsFormsRunner());
Using NHCookbookHelpers you don't even have to have a database server available, since it uses an in-memory SQLite database by default. If you want to use something else, like a local SQL server, you can specify a configuration instance to be used...