Nhibernate: one-to-many, based on multiple keys?
- by e36M3
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!