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; ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.