NHibernate 2.1 xml映射就像一个连接

时间:2015-09-22 07:20:55

标签: c# nhibernate nhibernate-mapping

我想在NHibernate 2.1中使用xml映射连接两个表。

父类(Table1)有一个属性,它是另一个类的List(Table2)。

现在class1有两个属性,我想要两个连接class2。

这是我试图在这个例子中简化的表格:

enter image description here

所以class1应该是:

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

就像我说的,这是一个简化的例子,因此我不想将属性从class2镜像到class1。我想要class1中的class2元素列表。 加入将是&#39; Type&#39;和&#39;数字&#39;。

1 个答案:

答案 0 :(得分:1)

你可以使用一个包:

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

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

可以找到有关该主题的更多信息here