NHibernate 多主键映射

标签 nhibernate

我有一张名为“Orderrow”的表。 Orderrow 有一个复合主键 (CPK),包含以下列:OrderId、ProductId、RowNumber

OrderId 和 ProductId 也是引用表 Order 和 Product 的外键。 RowNumber 在应用程序中生成。

我想知道这是如何在 NHibernate 中映射的,因为我只能设置 1 个 id 元素和 1 个生成器子元素。

最佳答案

以下是在 NHibernate 映射文件中使用复合 ID 属性的示例:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain" namespace="Domain.Model">

  <class name="Program" table="program">
    <composite-id>
      <key-property name="Id" column="id"></key-property>
      <key-property name="Prog" column="prog"></key-property>
      <key-property name="Site" column="site"></key-property>
    </composite-id>
    <property name="ActiveDate" column="active_date"/>
    <property name="Year" column="year"/>
  </class>

</hibernate-mapping>

关于NHibernate 多主键映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/852995/

相关文章:

nhibernate - 左连接、非重复和使用 QueryOver 进行分页

c# - Spring.NET - 对象引用未设置为对象的实例

c# - nhibernate 无法使用 LeftOuterJoin 解析属性(仅在 Visual Studio 2015 中)

NHibernate 提交数据库更改而无需显式调用保存或更新

c# - 将未知数量的列映射到字典

sql-server - 如何在 NHibernate 中使用 READPAST 提示?

nhibernate - 创建 SessionFactory 时使用了无效或不完整的配置

nhibernate - 使用一个连接而不是两个连接进行查询

c# - Nhibernate 标准 : Use of Expression. in()

c# - 如何以引用的 id 作为条件进行 NHibernate 查询?