流利code映射一个IDictionary&LT; SomeEntity,INT和GT ;? [英] Fluent code for mapping an IDictionary<SomeEntity, int>?
问题描述
我试图找出如何映射用流利的1.0 RTM一个IDictionary属性。
I'm trying to figure out how to map an IDictionary property in fluent 1.0 RTM.
这是我的理解这相当于一个三重关联。
From my understanding this translates to a ternary association.
例如:
class Bar
{
public IDictionary<SomeEntity, int> Foo {get; set;}
}
Bar.hbm.xml将包含:
Bar.hbm.xml would then contain:
<map name="Foo" table="BarFooTable">
<key column="..."/>
<index-many-to-many class="SomeEntity" column="SomeEntity_Id"/>
<element column="Value" type="int"/>
</map>
我会怎么得流利NHibernate的写入产生这种XML映射?
What would I have to write in fluent nhibernate to produce this mapping xml?
这里感兴趣的一点是,关键是实体类型而值是值类型。 (编辑:至少,这似乎从各种其他的例子和问题上的计算器左右浮动或谷歌群体,这是值,值或键键区分开来)
The point of interest here is that the key is an entity type while the value is a value type. (edit: At least, this seems to distinguish itself from the various other examples and questions floating around on stackoverflow or google groups, which are value-value or key-key)
经过多次实验,我可以产生一个映射的IDictionary&LT; SomeEntity,SomeEntity&GT;
(纯实体类型):
After much experimentation I can produce a mapping for an IDictionary<SomeEntity,SomeEntity>
(pure entity types):
HasManyToMany(x => x.Foo)
.AsMap("Key")
.AsTernaryAssociation("Key2", "Value")
;
我也能产生一个映射的的IDictionary&LT; INT,INT&GT;
(纯值类型):
HasMany(x => x.Foo)
.AsMap<int>("Key")
.Element("Value")
;
我甚至可以得到一些方法来制造用于映射的的IDictionary&LT; INT,someValue中)
,但没有一个NHibernate的接受
I can even get some way to producing a mapping for an IDictionary<int, SomeValue)
, although none that NHibernate will accept.
但我无法弄清楚如何产生一个的IDictionary℃的映射; someValue中,INT&GT;
这就是我想要的。有人可以提供一些建议吗?
But I cannot figure out how to produce a mapping for an IDictionary<SomeValue, int>
which is what I want. Can someone provide some tips?
推荐答案
我碰到了同样的问题,却高兴不起来,混合流畅和HBM映射。你可以看到我修复这里。
I ran into the same problem, and wasn't happy with mixing fluent and hbm mappings. You can see my fix here.
这篇关于流利code映射一个IDictionary&LT; SomeEntity,INT和GT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!