开发者

Nhibernate mapping - Can a child hold a reference to its parent collection?

开发者 https://www.devze.com 2023-01-21 15:10 出处:网络
I am new to NHibernate and I\'m trying it out by porting a small webforms app to use it. I am trying to figure out if its possible to map (hmb.xml maps) the following assignments:

I am new to NHibernate and I'm trying it out by porting a small webforms app to use it. I am trying to figure out if its possible to map (hmb.xml maps) the following assignments:

public class Foo
{
    public List<Bar> Children { get; se开发者_如何学编程t; }

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

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

The reason for the OwnerCollection reference is some generic manipulation of order (the real class has several different lists of objects.

I have managed to map everything, but can not see any way to establish the reference between OwnerCollection and Children.

Thanks, Mark H


parent:

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

child:

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


You can do that in code:

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

精彩评论

暂无评论...
验证码 换一张
取 消