Franki1986
Franki1986

Reputation: 1436

NHibernate 2.1 xml mapping like a join

I want to join two tables in NHibernate 2.1 with the xml mapping.

The parent class (Table1) has a property that is a List of the other class (Table2).

Now class1 has two properties that I want two join with class2.

These are the tables I tried to simplify for this example:

enter image description here

So class1 should be like:

public class class1{
    public IList<class2> Class2Items{ get; set;}
}

Like I said, this is a simplified example, so I don't want to mirror the properties from class2 to class1. I want a List of class2 elements in class1. The join would be for 'Type' and 'Number'.

Upvotes: 0

Views: 346

Answers (1)

Felice Pollano
Felice Pollano

Reputation: 33262

You can use a bag:

<class name="Class1" 
      table="Table1">

   <bag name="Items" cascade="all">
      <key column="FK_to_table1"/>
      <one-to-many 
         class="Class2"/>
   </bag>
</class>

more info on that topic can be found here.

Upvotes: 1

Related Questions