O'Reilly logo

Learning NHibernate 4 by Suhas Chatekar

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

Mapping by code

By now, you should have got a very good idea of what purpose the mappings serve. This knowledge will make understanding this section and the next very easy. At the beginning of the chapter, we discussed what is mapping by code and why it is built. So without much ado, let me get straight into the "mapping by code" feature of NH.

In mapping by code, mappings for each class can be declared in a separate and own class. It is also possible to declare the mappings in a single place by using the ModelMapper class. We would prefer to declare mappings for each entity in its own class. This class must inherit from another class provided by NHibernate called NHibernate.Mapping.ByCode.ClassMapping<T>. Whatever mappings you want to declare ...

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