Search code examples
c#nhibernatenhibernate-mapping

How to set entity name in NHibernate ManyToOne code mapping?


UPDATE: Fixed in version 5.2.


I'm converting a bunch of NHibernate .hbm.xml mappings to mapping by code. There are several many-to-one elements with an entity-name attribute:

<many-to-one name="Foo" column="FooId" class="Bar" entity-name="BarEntity"/>

which should translate to:

ManyToOne( c => c.Foo, map => 
{
     map.Column("FooId");
     map.EntityName("BarEntity"); // error
}

Unfortunately that does not work, because there is no EntityName in IManyToOneMapper. Why? Both IManyToManyMapper and IOneToManyMapper do have EntityName.

How do I fix this? Is there a workaround other than keeping the .hbm.xml mappings?


Solution

  • I guess it just got forgotten. I just checked 4.0.2 sources and didn't find anything. Not many people actually use entity names, so it probably hadn't been requested until now.

    I suggest to enter a feature request in the jira. You may want to implement it yourself and provide it to the community.