Fluent NHibernate index-many-to-many

断了今生、忘了曾经 提交于 2019-12-12 01:54:19

问题


Is there currently a way to use the equivalent of the index-many-to-many NHibernate tag in Fluent NHibernate?

The mapping I am trying to achieve was generated almost perfectly using AsMap on a HasManyToMany, apart from this one element specifying the index in the map:

Generated was: <index type=...

Should have been: <index-many-to-many class=...

EDIT: Currently the workaround I am using is to generate the partially incorrect mapping, manually editing the mapping file, commenting out the mapping code and then manually adding the corrected mapping file in place of Fluent NHibernate generating it from the commented out mapping code. Not ideal since any time the mapping changes I need to go through this process again, but once my mappings do not change this will not be so much of an issue.


回答1:


I solved this by using AsTernaryAssociation in addition to AsMap.

In summary, to map an IDictionary<KeyEntity,ValueEntity> I have the mapping:

HasManyToMany(x => x.TheDictionary)
    .AsMap("KeyColumn")
    .AsTernaryAssociation("KeyColumn", "ValueColumn");

Note that including type parameters causes this to not work for some reason (i.e. the below will throw a FluentNHibernate.Cfg.FluentConfigurationException)

HasManyToMany<ValueEntity>(x => x.TheDictionary)
    .AsMap<KeyEntity>("KeyColumn")
    .AsTernaryAssociation("KeyColumn", "ValueColumn");

I would be interested to know why the typed version does not work if anyone knows?



来源:https://stackoverflow.com/questions/8542298/fluent-nhibernate-index-many-to-many

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!