O'Reilly logo

NHibernate 3.0 Cookbook by Jason Dentler

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

Using dictionaries as entities

A little-known feature of NHibernate is EntityMode.Map. In this recipe, I'll show you how we can use this feature to persist entities without classes.

Getting ready

Set up a new console project for NHibernate by following these steps:

  1. Create a new console project.
  2. Add references to NHibernate.dll and NHibernate.ByteCode.Castle.dll.
  3. Add the following code to your main function:
    var nhConfig = new Configuration().Configure();
    var sessionFactory = nhConfig.BuildSessionFactory();
  4. Add an App.config file to your project.
  5. Inside the configuration element, declare a hibernate-configuration section, as shown:
    <configSections> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/> </configSections> ...

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