The object-relational mapper for .NET

How to

This page is converted from the old nhforge.org Wiki. First published by: ashern on 07-14-2011, Last revision by: ashern on 07-14-2011

ConventionModelMapper - change ManyToOne column name

Creating a convention to override the default column naming for your ManyToOne relationships is simple, as follows:

mapper.BeforeMapManyToOne += (insp, prop, map) =>

       map.Column(prop.LocalMember.GetPropertyOrFieldType().Name + "Id");

But, if any of the above are bi-directional relationships, be sure to equivalently map the inverse side's key as required for your collection types:

for set

mapper.BeforeMapSet += (insp, typ, map) => map.Key(km => 
       km.Column(typ.GetContainerEntity(insp).Name + "Id"));

for bag

mapper.BeforeMapBag += (insp, typ, map) => map.Key(km => 
       km.Column(typ.GetContainerEntity(insp).Name + "Id"));



© NHibernate Community 2016