Nhibernate的:一对许多人来说,基于多个键?多个、人来说、Nhibernate

2023-09-06 08:39:58 作者:丶小败北

让我们假设我有两个表

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, tB where 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 rows in 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>