我正在尝试解决这个问题,其中子类包含一组属性,但是引用表中不存在其中两个属性。
这两个属性存在于一个扩展表中,该扩展表具有返回基表的 FK。我不确定如何修改此 xml 以支持第一个加入的子类并为扩展表添加另一个连接。
我试图简单地为扩展表添加另一个连接子类,但是由于类名相同,映射无效。
<joined-subclass name="SESProgramAssociationAggregate.SESProgramAssociation" table="SESProgramAssociation" lazy="false">
<key>
<column name="BeginDate" />
<column name="EOId" />
<column name="PEOrganizationId" />
<column name="ProgramName" />
<column name="ProgramTypeId" />
<column name="UDI" />
</key>
<!-- PK properties -->
<property name="UDI" column="UDI" type="int" not-null="true" insert="false" />
<property name="ProgramTypeId" column="ProgramTypeId" type="int" not-null="true" insert="false" />
<property name="PEOrganizationId" column="PEOrganizationId" type="int" not-null="true" insert="false" />
<property name="BeginDate" column="BeginDate" type="date" not-null="true" insert="false" />
<property name="ProgramName" column="ProgramName" type="string" length="60" not-null="true" insert="false" />
<property name="EOId" column="EOId" type="int" not-null="true" insert="false" />
<!-- Properties -->
<property name="Eligibility" column="Eligibility" type="bool" />
<property name="SESDescriptorId" column="SESDescriptorId" type="int" not-null="true" />
<property name="SEHoursPerWeek" column="SEHoursPerWeek" type="decimal" />
<property name="HoursPerWeek" column="HoursPerWeek" type="decimal" />
<property name="MultiplyD" column="MultiplyD" type="bool" />
<property name="MFragile" column="MFragile" type="bool" />
<property name="LastEvalDate" column="LastEvalDate" type="date" />
<property name="ReviewDate" column="ReviewDate" type="date" />
<property name="BeginDate" column="BeginDate" type="date" />
<property name="EndDate" column="EndDate" type="date" />
<property name="EventCode" column="EventCode" type="int" />
<property name="WrittenConsentDate" column="WrittenConsentDate" type="date" />
</joined-subclass>
生成的最终查询失败,因为它尝试从不存在的 SESProgramAssociation 表中引用 EventCode 和 WrittenConsentDate。它们实际上存在于扩展表中。
我不确定如何修改此 xml 以将这些字段指向扩展表,以便生成的查询实际上从该表中提取它们而不是错误的。非常感谢任何帮助,这是我第一次体验 NHirate,不用说,这并不好玩!
在 Frédéric 的建议下,我更新了但得到了这个错误:
NHibernate.dll 中出现“NHibernate.MappingException”类型的异常,但未在用户代码中处理
附加信息:EdFi.Ods.Entities.NHibernate.Mappings.SqlServer.StudentProgramAssociationBase.hbm.xml(79,8):XML 验证错误:命名空间“urn:nhibernate-mapping-2.2”中的元素“joined-subclass”无效命名空间“urn:nhibernate-mapping-2.2”中的子元素“join”。预期的可能元素列表:'属性、多对一、一对一、组件、动态组件、属性、任何、映射、集合、列表、包、idbag、数组、原始数组、连接子类,加载器,sql-insert,sql-update,sql-delete,结果集,查询,sql-query'在命名空间'urn:nhibernate-mapping-2.2'中。