Nhibernate: one-to-many, based on multiple keys?
Posted
by e36M3
on Stack Overflow
See other posts from Stack Overflow
or by e36M3
Published on 2009-09-17T00:52:25Z
Indexed on
2010/06/17
1:02 UTC
Read the original article
Hit count: 336
Lets assume I have two tables
Table tA
ID
ID2
SomeColumns
Table tB
ID
ID2
SomeOtherColumns
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:
select tB.* from tA, tB where tA.ID = tB.ID and tA.ID2 = tB.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>
Thanks!
© Stack Overflow or respective owner