nHibernate,不存在具有给定标识符的行 [英] nHibernate, No row with the given identifier exists
本文介绍了nHibernate,不存在具有给定标识符的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个与此类似的映射.
I have a mapping along the lines of this.
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="Model.Entities" schema="etl" assembly="Model" default-lazy="false">
<class name="Model.Entities.DataField, Model" table="mdm_field">
<id name="FieldId" column="field_id" type="int">
<generator class="native" />
</id>
<many-to-one name="KeyField" class="Model.Entities.Key, Model" column="field_id" />
</class>
</hibernate-mapping>
现在数据库中的mdm_field表中的field_id有时具有在相关key_field表中不存在的值,因此基本上破坏了参照完整性.因此,当我加载实体时,会收到错误消息不存在具有给定标识符的行".如何配置映射以在这种情况下使用,以免在这种情况下消失.
Now in the database the field_id in the mdm_field table sometimes has a value that does not exist in the related key_field table, so it is basically broken referential integrity. Because of this when I load the entity I get an error "No row with the given identifier exists". How do I configure the mapping to work with this situation so it will not die on this situation.
推荐答案
好,我找到了答案.添加
Ok, I found the answer. Add the
not-found="ignore"
属性KeyField
:
<many-to-one name="KeyField" not-found="ignore" class="Model.Entities.Key, Model" column="field_id" />
这篇关于nHibernate,不存在具有给定标识符的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文