简体   繁体   English

NHibernate 2.1 xml映射就像一个联接

[英]NHibernate 2.1 xml mapping like a join

I want to join two tables in NHibernate 2.1 with the xml mapping. 我想用xml映射将NHibernate 2.1中的两个表连接起来。

The parent class (Table1) has a property that is a List of the other class (Table2). 父类(Table1)具有一个属性,该属性是另一个类(Table2)的列表。

Now class1 has two properties that I want two join with class2. 现在class1有两个属性,我想两个与class2联接。

These are the tables I tried to simplify for this example: 这些是我为该示例简化的表:

在此处输入图片说明

So class1 should be like: 所以class1应该像这样:

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. 就像我说的那样,这是一个简化的示例,因此我不想将属性从class2镜像到class1。 I want a List of class2 elements in class1. 我想要Class1中的class2元素列表。 The join would be for 'Type' and 'Number'. 该联接将用于“类型”和“数字”。

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 . 有关该主题的更多信息,请参见此处

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM