Fluent NHibernate index-many-to-many

2019-09-09 07:09发布

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条回答
我欲成王,谁敢阻挡
2楼-- · 2019-09-09 07:38

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?

查看更多
登录 后发表回答