Mapping by code - how to get TableName for class in ModelMapper.AfterMapClass event?

87 views
Skip to first unread message

Filip Kinsky

unread,
Jul 6, 2011, 4:30:28 PM7/6/11
to nhu...@googlegroups.com
I need to access TableName of mapped class in AfterMapClass to be able to setup generator properly - is there any solution how to obtain HbmClass instance or any other object with TableName accessible? My code looks like this:

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

I wasn't able to find any other method how to get this information other than using reflection - I hope I just missed something obvious...

Filip Kinsky

unread,
Jul 14, 2011, 10:40:52 AM7/14/11
to nhu...@googlegroups.com
I've just raised JIRA issue for this: https://nhibernate.jira.com/browse/NH-2794

John Davidson

unread,
Jul 14, 2011, 11:32:11 AM7/14/11
to nhu...@googlegroups.com
Did you check in the NHibernate.Mapping namespace?

John Davidson

On Thu, Jul 14, 2011 at 10:40 AM, Filip Kinsky <fi...@filovo.net> wrote:
I've just raised JIRA issue for this: https://nhibernate.jira.com/browse/NH-2794

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/fZqTrRy07w8J.

To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Filip Kinsky

unread,
Jul 15, 2011, 2:20:44 AM7/15/11
to nhu...@googlegroups.com
What exactly do you mean?

Ricardo Peres

unread,
Jul 15, 2011, 3:55:08 AM7/15/11
to nhusers
Have you tried something like:

mapper.AfterMapClass += (IModelInspector modelInspector, Type type,
IClassAttributesMapper classCustomizer) =>
{
var table = cfg.ClassMappings.Where(x => x.EntityName ==
"MyEntityName").Select(x => x.RootTable);
};

?

On Jul 15, 7:20 am, Filip Kinsky <fi...@filovo.net> wrote:
> What exactly do you mean?

Filip Kinsky

unread,
Jul 15, 2011, 4:11:06 AM7/15/11
to nhu...@googlegroups.com
This doesn't work, because class mappings are added to configuration after AfterMapClass is invoked. That means that when AfterMapClass is raised, cfg.ClassMappings does not contain mapping definition for the class yet - I just tried it. My code looks like this:


var cfg = new Configuration...

var mapper = new ModelMapper();
AddMappingConventions(mapper); //register BeforeMapClass + AfterMapClass event handlers
AddMappingsForAllEntities(mapper); //mapper.Class<>()

var hbmMappings = mapper.CompileMappingForAllExplicitAddedEntities();
cfg.AddDeserializedMapping(hbmMappings, null);

Fabio Maulo

unread,
Jul 16, 2011, 5:35:13 PM7/16/11
to nhu...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages