Quantcast
Channel: ConventionModelMapper - change ManyToOne column name
Viewing all articles
Browse latest Browse all 3

ConventionModelMapper - change ManyToOne column name

$
0
0
Current revision posted to How to by ashern on 14/07/2011 02:37:37 a.m.

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"))> 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"))> map.Key(km => 
km.Column(typ.GetContainerEntity(insp).Name + "Id"));

etc...

 


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images