We can also configure NHibernate entirely in code. In this recipe, I'll show you how to use the NHibernate.Cfg.Loquacious
namespace to configure NHibernate.
Complete the
Eg.Core
model and mapping recipes from Chapter 1.Add a console application project to your solution named
ConfigByCode
.Set it as the Startup project for your solution.
In the
ConfigByCode
project, add references toNHibernate.dll
andNHibernate.ByteCode.Castle.dll
in theLib
folder.In
ConfigByCode
, add a reference to theEg.Core
project.
Add an
App.config
file with this configuration:<?xml version="1.0" encoding="utf-8" ?> <configuration> <connectionStrings> <add name="db" connectionString="Server=.\SQLExpress; Database=NHCookbook; Trusted_Connection=SSPI"/> </connectionStrings> </configuration>
In
Program.cs
, add the followingusing
statements:using NHibernate.ByteCode.Castle; using NHibernate.Cfg; using NHibernate.Cfg.Loquacious...