gpt4 book ai didi

exception - NHibernate "Repeated column in mapping for collection"异常

转载 作者:行者123 更新时间:2023-12-04 04:39:36 24 4
gpt4 key购买 nike

考虑以下 NHibernate 映射,并注意注释的属性。这些列与 key 相同和 index map 中指定的列.当我删除注释(因此包括属性的 TypeOfPartUnitId 列)时,我收到“映射集合中的重复列”异常。

<map name="Parts" table="ActiveUnitParts" lazy="false">
<key column="UnitId" />
<index column="TypeOfPart" type="integer"/>
<composite-element class="ActiveUnitPart">
<property name="Id" />
<property name="CreationDate" />
<property name="PartInfo"/>
<property name="Remarks"/>
<!-- <property name="TypeOfPart" /> -->
<!-- <property name="UnitId" /> -->
</composite-element>
</map>

我在代码中需要的是一个 Dictinonary<TypeOfpart, ActiveUnitPart> .但我的问题是属性值 UnitIdTypeOfPart未在 ActiveUnitPart 中设置 Dictinonary<TypeOfpart, ActiveUnitPart> 中的实例.

是的,该单元的相关部分列表已加载,是的,字典中的键与正确的部分相关。但我不明白为什么我不能引用 TypeOfPartUnitId填充 ActiveUnitPart 中的属性本身也是。

我该如何解决或解决这个问题?

为什么我需要这个的动机:
我必须能够与 ActiveUnitPart 一起工作s 没有引用相关 Unit ( UnitId )

编辑 1:
我知道我可以拦截 Parts的setter Unit 的属性(property)并遍历 Dictinonary<TypeOfpart, ActiveUnitPart>在代码中设置值,但它似乎是 hack想学更优雅的 NHibernate如果可能的话,完成它的方法。

最佳答案

有可能,只需将映射从 column 更改为至 formula .实现这一目标的最佳方法是:

<property name="TypeOfPart" formula="TypeOfPart" insert="false" update="false" />
<property name="UnitId" formula="UnitId" insert="false" update="false" />

关于exception - NHibernate "Repeated column in mapping for collection"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19110183/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com