O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

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

Time for action – Creating the mapping classes

To make our life very simple, we will use Fluent NHibernate to map our model to the underlying database. Fluent NHibernate allows us to define the mapping in code, in a type-safe way.

  1. Add a reference to FluentNHibernate.dll and to NHibernate.dll, which you can locate in the lib folder, as shown in the following screenshot:
    Time for action – Creating the mapping classes
  2. Add a new class to the project and call it CategoryMap. Add using FluentNHibernate.Mapping; to the file.
  3. Make the class inherit from ClassMap<Category>.
  4. Add a default constructor to the class and define the mapping for the Id.
  5. In the constructor, add Id(x =>x.Id);, that is, we use the ...

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