C# nhibernate中具有复合密钥的多对一映射

C# nhibernate中具有复合密钥的多对一映射,c#,nhibernate,nhibernate-mapping,C#,Nhibernate,Nhibernate Mapping,我有以下nhibernate映射,我想用一对一映射将复合键值保存到其他实体TimesheetCellTransactionLine中的单独列中。有什么想法吗?以下内容不保存两个外键列中的值passes null <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ManpowerUK.Indigo.Domain" namespace="ManpowerUK.Indigo.Domain.Tim

我有以下nhibernate映射,我想用一对一映射将复合键值保存到其他实体TimesheetCellTransactionLine中的单独列中。有什么想法吗?以下内容不保存两个外键列中的值passes null

<hibernate-mapping
    xmlns="urn:nhibernate-mapping-2.2"
    assembly="ManpowerUK.Indigo.Domain"
    namespace="ManpowerUK.Indigo.Domain.Timesheets">
    <class name="CMSTimesheetCell" lazy="false" table="vw_TimesheetCell" mutable="false">
        <composite-id >
            <key-property name="TimesheetCellId"/>
            <key-property name="TimesheetCellVersion" column="Version"/>
        </composite-id>
        <property name="TimesheetId" not-null="true" />
        <property name="IsRemoved" />
    </class>
</hibernate-mapping>


<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ManpowerUK.Indigo.Domain" namespace="ManpowerUK.Indigo.Domain">
  <class name="TimesheetCellTransactionLine" lazy="false">
      <id column="TransactionLineId"/>
      <many-to-one name="Timesheet" class="ManpowerUK.Indigo.Domain.Timesheets.TimesheetCellWrite" column="TimesheetId" not-null="true" lazy="proxy"/>
      <many-to-one name="CMSTimesheetCell" class="ManpowerUK.Indigo.Domain.Timesheets.CMSTimesheetCell" not-null="true" lazy="proxy" cascade="none">
        <column name="TimesheetCellId"/>
        <column name="TimesheetCellVersion"/>
      </many-to-one>
  </class>
</hibernate-mapping>

我通过添加额外的属性映射来插入复合键来解决这个问题

  <property name="TimesheetCellId" not-null="true" />
  <property name="TimesheetCellVersion" not-null="true" />

在获取时,我使用了以下映射:insert和update false以及cascade none

 <many-to-one name="CMSTimesheetCell" class="ManpowerUK.Indigo.Domain.Timesheets.CMSTimesheetCell" not-null="true" lazy="proxy" cascade="none" insert="false" update="false">
    <column name="TimesheetCellId"/>
    <column name="TimesheetCellVersion"/>
  </many-to-one>

完整的映射文件如下所示

     <?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="ManpowerUK.Indigo.Domain" namespace="ManpowerUK.Indigo.Domain">
  <class name="TimesheetCellTransactionLine"  lazy="false">
      <id column="TransactionLineId" />
      <property name="TimesheetCellId" not-null="true" />
      <property name="TimesheetCellVersion" not-null="true" />
           <many-to-one name="CMSTimesheetCell" class="ManpowerUK.Indigo.Domain.Timesheets.CMSTimesheetCell" not-null="true" lazy="proxy" cascade="none" insert="false" update="false">
        <column name="TimesheetCellId"/>
        <column name="TimesheetCellVersion"/>
      </many-to-one>
    </class>
</hibernate-mapping>

我将用利用代码映射的解决方案来补充这个答案:

 mapping.Class<TimesheetCellTransactionLine>(classMapper =>
 {
      classMapper.ManyToOne(
            line => line.CMSTimesheetCell,
            columns
            (
                 columnMapper => columnMapper.Name("TimesheetCellId"),
                 columnMapper => columnMapper.Name("TimesheetCellVersion")
            )
      );
 });
mapping.Class(classMapper=>
{
classMapper.ManyToOne(
line=>line.CMSTimesheetCell,
柱
(
columnMapper=>columnMapper.Name(“TimesheetCellId”),
columnMapper=>columnMapper.Name(“TimesheetCellVersion”)
)
);
});

您的
TimesheetCellTransactionLine
似乎是从更大的映射中提取的,您提供的代码段看起来无效且未经测试(
子类
在类定义之外)。你能写一封信吗?