ModelMapper.AfterMapClass event or ClassMapper do not provide any access to HbmClass instance

Description

I was looking for any possibility how to retrieve some attributes of mapped class (= HbmClass instance) being processed in AfterMapClass event for further processing, but the ClassMapper.classMapping field is unfortunately not publicly accessible. There should be public read-only property defined for this field. My particular use-case is I need to retrieve table name defined for the class to use it in table based HighLow generator for Id field of mapped entity-classes:

modelMapper.AfterMapClass += (mi, t, map) =>
{
map.Id(x =>
{
var tableName = ???;
x.Column("ID");
x.Generator(Generators.HighLow, gm => gm.Params(new { where = String.Format("TABLENAME = '{0}'", tableName) }));
});
}

https://groups.google.com/forum/#!topic/nhusers/qXKd2XD4OzQ

Environment

None

Activity

Filip Kinský 
July 17, 2011 at 10:37 AM

Thanks for your response, Fabio. Your suggestion means, that I should define the generator parameter in User mapping definition "block" (which is placed in a ClassMapping class in some other assembly in my case - modular application) if I understand it right. This isn't solution I can accept, because it decentralizes the responsibility for generator configuration (at least part of it) and it'd be PITA to move to another generator strategy. I can workaround it of course, but I think the possibility to retrieve actual class mapping configuration in AfterClassMap would be quite meaningful in this and probably also other similar cases.

Fabio Maulo 
July 16, 2011 at 4:45 PM

Filip,
in the same way you apply the table name in BeforeClassMap you can apply the generatos parameters/restrictions.
In the same place where you override your TableNaming convention you can override the generatos parameters/restrictions.

Fabio Maulo 
July 16, 2011 at 4:42 PM

Ricardo, you have to use the auto-quote configuration and that is all.

Filip Kinský 
July 15, 2011 at 7:30 PM

This is just one sample case.. I can figure out some other example - what if table name length is limited to 30 characters (Oracle) and my entity name is longer etc. The same could be with column names for some other post-processing etc. I think it's fully meaningful to have some mean to access entity mapping metadata in AfterMapClass event. I could build some massive convention algorithm to produce table names (plurals + shorten long table names with short name collision handling etc.), but KISS + there can always be some exception.

Ricardo Peres 
July 15, 2011 at 4:53 PM

Not directly related, but for the table or the column names, you should always use the syntax `USER`, where the ` gets translated to the DB-specific escape character.

Won't Fix

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created July 14, 2011 at 2:39 PM
Updated July 17, 2011 at 10:37 AM
Resolved July 14, 2011 at 3:17 PM
Who's Looking?