本文介绍了Nhibernate的:一对许多人来说,基于多个键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我有两个表

Table tA
    ID
    ID2
    SomeColumns
Table tB
   ID
   ID2
   SomeOtherColumns

我希望创建一个对象,让我们把它叫做对象A(基于TA),这将有一个一对多的关系,对象B(以TB)。在我的例子不过,我需要使用ID和ID2相结合的外键。如果我在写SQL就应该是这样的:

I am looking to create a Object let's call it ObjectA (based on tA), that will have a one-to-many relationship to ObjectB (based on tB). In my example however, I need to use the combination of ID and ID2 as the foreign key. If I was writing SQL it would look like this:

选择TB。*从TA,TB其中,tA.ID = tB.ID和tA.ID2 = tB.ID2;

select tB.*from tA, tBwhere tA.ID = tB.ID and tA.ID2 = tB.ID2;

我知道,在TA每个ID / ID2组合,我应该有许多行结核病,为此我知道这是一个一对多的组合。显然,集合下面是不够的,例如映射,只需要一键考虑

I know that for each ID/ID2 combination in tA I should have many rowsin tB, therefor I know it's a one-to-many combination. Clearly the below set is not sufficient for such mapping as it only takes one key into account.

<set name="A2" table="A2" generic="true" inverse="true" >
  <key column="ID" />
  <one-to-many class="A2" />
</set>

谢谢!

推荐答案

您是否尝试过这个?

<set name="A2" table="A2" generic="true" inverse="true" >
  <key>
    <column ="ID" />
    <column ="ID2" />
  </key>
  <one-to-many class="A2" />
</set>

这篇关于Nhibernate的:一对许多人来说,基于多个键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 05:50