流利的NHibernate索引(多对多) [英] Fluent NHibernate index-many-to-many

查看:104
本文介绍了流利的NHibernate索引(多对多)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前是否有一种方法可以在Fluent NHibernate中使用与index-many-to-many NHibernate标签相同的内容?

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

我试图实现的映射是在HasManyToMany上使用AsMap几乎完美生成的,除了这一元素指定了映射中的索引:

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:

生成为: <index type=...

应该是: <index-many-to-many class=...

当前,我正在使用的解决方法是生成部分不正确的映射,手动编辑映射文件,注释掉映射代码,然后手动添加更正的映射文件,以代替Fluent NHibernate从注释掉的映射代码生成它.这并不理想,因为任何时候映射发生更改,我都需要再次执行此过程,但是一旦映射不更改,就不会有太大问题了.

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.

推荐答案

除了AsMap之外,我还使用AsTernaryAssociation解决了这个问题.

I solved this by using AsTernaryAssociation in addition to AsMap.

总而言之,要映射IDictionary<KeyEntity,ValueEntity>,我具有以下映射:

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

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

请注意,包含类型参数会导致此操作由于某种原因而无法正常工作(即以下内容将抛出FluentNHibernate.Cfg.FluentConfigurationException)

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?

这篇关于流利的NHibernate索引(多对多)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆