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; }
}
精彩评论