O'Reilly logo

NHibernate 4.x Cookbook - Second Edition by Jason Dentler, Alexander Zaytsev, Gunnar Liljas

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 convention

In large object models, you will notice that many aspects of the mappings are repetitive. Maybe the Comb generator should generate all POIDs or all properties referencing a class without an Id property should be treated as a component mapping. By setting up mapping conventions, you can potentially avoid all explicit mappings and instead let the code structure do the work for you.

Getting ready

Complete the Getting ready instructions at the beginning of this chapter.

How to do it…

  1. Add a folder named MappingByConvention to the MappingRecipes project.
  2. Add a class named MyModelMapper to the folder:
    using System.Collections.Generic; using System.Linq; using System.Reflection; using NH4CookbookHelpers.Mapping.Model; using NHibernate.Mapping.ByCode; ...

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