2010-10-21 51 views
1

我是NHibernate的新手,我試着通過移植一個小型webforms應用程序來使用它。我想弄清楚如果可能的映射(hmb.xml地圖)分配如下:Nhibernate映射 - 孩子可以持有對其父集合的引用嗎?

public class Foo 
{ 
    public List<Bar> Children { get; set; } 

    public void AddBar(Bar b) 
    { 
     Children.Add(b); 
     b.OwnerCollection = Children; 
    } 
} 

public class Bar 
{ 
    public Foo Parent { get; set; } 
    public IList OwnerCollection { get; set; } 
} 

的原因OwnerCollection參考是爲了一些通用的操作(真正的類的對象有幾個不同的列表。

我已成功地映射了一切,但不能看到任何方式建立OwnerCollection與兒童之間的參考

謝謝, 中H

回答

1

父:

<set name="Children" inverse="true" cascade="all-delete-orphan"> 
<key column="parent_id"/> 
<one-to-many class="Child"/> 
</set> 

孩子:

<many-to-one name="Parent" column="parent_id" not-null="true"/> 
+0

對不起,如果我不清楚。我有Parent屬性映射工作,我需要也映射OwnerCollection。 – 2010-10-21 21:09:41

0

你可以在代碼:

public IList<Bar> OwnerCollection 
{ 
    get { return Parent.Children; } 
}