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…
Add a folder named
MappingByConvention
to theMappingRecipes
project.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; namespace MappingRecipes.MappingByConvention { public class MyModelMapper : ConventionModelMapper { public MyModelMapper() { IsEntity((t, declared) => typeof(Entity).IsAssignableFrom(t) && ...