Configuring NHibernate with App.config or Web.config

Another common method for configuring NHibernate uses a .NET configuration file. In this recipe, we will show you how to configure NHibernate using App.config or Web.config files, to provide an identical configuration to the previous recipe.

Getting ready

  1. Complete the steps in the Installing NHibernate recipe.
  2. Add a console application project named ConfigByAppConfig to your solution.
  3. Set it as the Startup project for your solution.
  4. Install NHibernate to the ConfigByAppConfig project using the NuGet Package Manager Console.
  5. In ConfigByAppConfig, add a reference to the Eg.Core project.
  6. Add an App.config file to your project.

How to do it…

  1. Open the App.config file.
  2. Declare a section for the NHibernate configuration, ...

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.