NHibernate Forge
The official new home for the NHibernate for .NET community

ConventionModelMapper - change ManyToOne column name

Wiki Page Hierarchy

Pages

Page Details

First published by:
ashern
on 07-14-2011
Last revision by:
ashern
on 07-14-2011
1 person found this article useful.
Article
Comments (1)
History (3)
100% of people found this useful

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"));

etc...

 

Recent Comments

By: rgmoon Posted on 09-20-2011 2:46

Info regarding software is always important and we have to learn the art of describing different codes and software. Such model papers can help us a lot to solve our problems. Thanks for sharing this nice and informative post.

www.findkcb.com/aids-related-cancers

View All
Powered by Community Server (Commercial Edition), by Telligent Systems