在 nhibernate4 中创建没有外键的一对多关系
Create relation one-to-many without Foreign Key in nhibernate4
我是 NHibernate 4 的新手,我尝试在 DB2 中的两个 table 之间创建一对多关系,table 没有外键,我无法编辑 table。
调试应用程序时,我在 .saveorupdate 方法中发现了错误。
tables 包含:
TLDMAIN->文章摘要
TLDDETAIL->文章详情
在table的映射下,
TLDMAIN
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateExample2"
namespace="NHibernateExample2.NHibernateMappings"
schema="RM2T4"
>
<class name="TLDMAIN" table="TLDMAIN">
<id name="DGINAD" column="DGINAD" type="System.String">
<generator class="assigned" />
</id>
<property name="DGSEDE" column="DGSEDE" type="System.String" />
<property name="DGZONA" column="DGZONA" type="System.String" />
<property name="DGCEOP" column="DGCEOP" type="System.String" />
<property name="DGSEDEC" column="DGSEDEC" type="System.String" />
<property name="DGZONAC" column="DGZONAC" type="System.String" />
<property name="DGCEOPC" column="DGCEOPC" type="System.String" />
<property name="DGRLAV" column="DGRLAV" type="System.String" />
<property name="DGCFDDL" column="DGCFDDL" type="System.String" />
<property name="DGCFLAV" column="DGCFLAV" type="System.String" />
<property name="DGDTDOM" column="DGDTDOM" type="System.String" />
<property name="DGTIPREGO" column="DGTIPREGO" type="System.String" />
<property name="DGDTINTER" column="DGDTINTER" type="System.String" />
<property name="DGNRATE" column="DGNRATE" type="System.Int32" />
<property name="DGIMPRATA" column="DGIMPRATA" type="System.Decimal" />
<property name="DGPRECALC" column="DGPRECALC" type="System.String" />
<property name="DGSTCORR" column="DGSTCORR" type="System.String" />
<property name="DGTIMEST" column="DGTIMEST" type="System.String" />
<property name="DGNOTE" column="DGNOTE" type="System.String" />
<bag name="periodi" table="TLDDETAIL" lazy="false">
<key column="DDINAD" />
<one-to-many class="NHibernateExample2.NHibernateMappings.TLDDETAIL" />
</bag>
</class>
</hibernate-mapping>
TLD详细信息
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateExample2"
namespace="NHibernateExample2.NHibernateMappings"
schema="RM2T4"
>
<class name="TLDDETAIL" table="TLDDETAIL">
<id name="DDINAD" column="DDINAD" type="System.String">
<generator class="assigned" />
</id>
<property name="DDANNO" column="DDANNO" type="System.Int32" />
<property name="DDTRIM" column="DDTRIM" type="System.Int32" />
<property name="DDPROG" column="DDPROG" type="System.Int32" />
<property name="DDORERET" column="DDORERET" type="System.Int32" />
<property name="DDTIPCAL" column="DDTIPCAL" type="System.String" />
<property name="DDRETEFF" column="DDRETEFF" type="System.Decimal" />
<property name="DDSETALL" column="DDSETALL" type="System.String" />
<property name="DDSETT1" column="DDSETT1" type="System.String" />
<property name="DDSETT2" column="DDSETT2" type="System.String" />
<property name="DDSETT3" column="DDSETT3" type="System.String" />
<property name="DDSETT4" column="DDSETT4" type="System.String" />
<property name="DDSETT5" column="DDSETT5" type="System.String" />
<property name="DDSETT6" column="DDSETT6" type="System.String" />
<property name="DDSETT7" column="DDSETT7" type="System.String" />
<property name="DDSETT8" column="DDSETT8" type="System.String" />
<property name="DDSETT9" column="DDSETT9" type="System.String" />
<property name="DDSETT10" column="DDSETT10" type="System.String" />
<property name="DDSETT11" column="DDSETT11" type="System.String" />
<property name="DDSETT12" column="DDSETT12" type="System.String" />
<property name="DDSETT13" column="DDSETT13" type="System.String" />
<property name="DDSETT14" column="DDSETT14" type="System.String" />
<property name="DDSETT15" column="DDSETT15" type="System.String" />
<property name="DDINTEGR" column="DDINTEGR" type="System.String" />
<property name="DATEPAG" column="DATEPAG" type="System.String" />
<property name="FLAGPAG" column="FLAGPAG" type="System.String" />
<property name="DDPARTITA" column="DDPARTITA" type="System.String"/>
<property name="DDPROGPART" column="DDPROGPART" type="System.String"/>
</class>
</hibernate-mapping>
错误是
没有坚持者:NHibernateExample2.NHibernateMappings.TLDMAIN
在google中我找到了这个错误的原因,它是映射错误,但我没有找到这个。
谢谢帮助!!!
该错误似乎与外键问题无关。似乎是 NHibernate 找不到 XML 文件。 "common" 问题通常是三个:
- 必须使用 Build Action = Embedded Resource 设置 XML 文件(在其属性中)
- 在有
<session-factory>
部分的配置文件中(通常是 app.config/web.config),应该有一个 <mapping assembly="NHibernateExample2"/>
(或者任何带有映射的程序集命名)
- 第三种可能性,在加载 NHibernate 配置的地方,也许您忘记了执行
configuration.Configure()
(因为执行 NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
还不够,您必须执行 configuration.Configure()
)
我是 NHibernate 4 的新手,我尝试在 DB2 中的两个 table 之间创建一对多关系,table 没有外键,我无法编辑 table。 调试应用程序时,我在 .saveorupdate 方法中发现了错误。 tables 包含:
TLDMAIN->文章摘要
TLDDETAIL->文章详情
在table的映射下,
TLDMAIN
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateExample2"
namespace="NHibernateExample2.NHibernateMappings"
schema="RM2T4"
>
<class name="TLDMAIN" table="TLDMAIN">
<id name="DGINAD" column="DGINAD" type="System.String">
<generator class="assigned" />
</id>
<property name="DGSEDE" column="DGSEDE" type="System.String" />
<property name="DGZONA" column="DGZONA" type="System.String" />
<property name="DGCEOP" column="DGCEOP" type="System.String" />
<property name="DGSEDEC" column="DGSEDEC" type="System.String" />
<property name="DGZONAC" column="DGZONAC" type="System.String" />
<property name="DGCEOPC" column="DGCEOPC" type="System.String" />
<property name="DGRLAV" column="DGRLAV" type="System.String" />
<property name="DGCFDDL" column="DGCFDDL" type="System.String" />
<property name="DGCFLAV" column="DGCFLAV" type="System.String" />
<property name="DGDTDOM" column="DGDTDOM" type="System.String" />
<property name="DGTIPREGO" column="DGTIPREGO" type="System.String" />
<property name="DGDTINTER" column="DGDTINTER" type="System.String" />
<property name="DGNRATE" column="DGNRATE" type="System.Int32" />
<property name="DGIMPRATA" column="DGIMPRATA" type="System.Decimal" />
<property name="DGPRECALC" column="DGPRECALC" type="System.String" />
<property name="DGSTCORR" column="DGSTCORR" type="System.String" />
<property name="DGTIMEST" column="DGTIMEST" type="System.String" />
<property name="DGNOTE" column="DGNOTE" type="System.String" />
<bag name="periodi" table="TLDDETAIL" lazy="false">
<key column="DDINAD" />
<one-to-many class="NHibernateExample2.NHibernateMappings.TLDDETAIL" />
</bag>
</class>
</hibernate-mapping>
TLD详细信息
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="NHibernateExample2"
namespace="NHibernateExample2.NHibernateMappings"
schema="RM2T4"
>
<class name="TLDDETAIL" table="TLDDETAIL">
<id name="DDINAD" column="DDINAD" type="System.String">
<generator class="assigned" />
</id>
<property name="DDANNO" column="DDANNO" type="System.Int32" />
<property name="DDTRIM" column="DDTRIM" type="System.Int32" />
<property name="DDPROG" column="DDPROG" type="System.Int32" />
<property name="DDORERET" column="DDORERET" type="System.Int32" />
<property name="DDTIPCAL" column="DDTIPCAL" type="System.String" />
<property name="DDRETEFF" column="DDRETEFF" type="System.Decimal" />
<property name="DDSETALL" column="DDSETALL" type="System.String" />
<property name="DDSETT1" column="DDSETT1" type="System.String" />
<property name="DDSETT2" column="DDSETT2" type="System.String" />
<property name="DDSETT3" column="DDSETT3" type="System.String" />
<property name="DDSETT4" column="DDSETT4" type="System.String" />
<property name="DDSETT5" column="DDSETT5" type="System.String" />
<property name="DDSETT6" column="DDSETT6" type="System.String" />
<property name="DDSETT7" column="DDSETT7" type="System.String" />
<property name="DDSETT8" column="DDSETT8" type="System.String" />
<property name="DDSETT9" column="DDSETT9" type="System.String" />
<property name="DDSETT10" column="DDSETT10" type="System.String" />
<property name="DDSETT11" column="DDSETT11" type="System.String" />
<property name="DDSETT12" column="DDSETT12" type="System.String" />
<property name="DDSETT13" column="DDSETT13" type="System.String" />
<property name="DDSETT14" column="DDSETT14" type="System.String" />
<property name="DDSETT15" column="DDSETT15" type="System.String" />
<property name="DDINTEGR" column="DDINTEGR" type="System.String" />
<property name="DATEPAG" column="DATEPAG" type="System.String" />
<property name="FLAGPAG" column="FLAGPAG" type="System.String" />
<property name="DDPARTITA" column="DDPARTITA" type="System.String"/>
<property name="DDPROGPART" column="DDPROGPART" type="System.String"/>
</class>
</hibernate-mapping>
错误是 没有坚持者:NHibernateExample2.NHibernateMappings.TLDMAIN
在google中我找到了这个错误的原因,它是映射错误,但我没有找到这个。
谢谢帮助!!!
该错误似乎与外键问题无关。似乎是 NHibernate 找不到 XML 文件。 "common" 问题通常是三个:
- 必须使用 Build Action = Embedded Resource 设置 XML 文件(在其属性中)
- 在有
<session-factory>
部分的配置文件中(通常是 app.config/web.config),应该有一个<mapping assembly="NHibernateExample2"/>
(或者任何带有映射的程序集命名) - 第三种可能性,在加载 NHibernate 配置的地方,也许您忘记了执行
configuration.Configure()
(因为执行NHibernate.Cfg.Configuration configuration = new NHibernate.Cfg.Configuration();
还不够,您必须执行configuration.Configure()
)