views:

24

answers:

2

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; 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; }
}

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

+1  A: 

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"/>
Tim Mahy
Sorry if I wasn't clear. I have the Parent property mapping working, I need the OwnerCollection to be mapped as well.
Mark Huber
A: 

You can do that in code:

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