Let's say I have a class Child which is contained in different other classes (ParentA and ParentB in this example). The following simple case demonstrates a simple model where ParentA and ParentB both contain a set of Child objects.
public class ParentA
{
public virtual ISet<Child> Children { get; set; }
}
public class ParentB
{
public virtual ISet<Child> Children { get; set; }
}
public class Child
{
}
Navigation from parent to child is no problem in this simple case. But now I want to be able to navigate to the parent. Typically I would introduce an interface IParent)
public class ParentA: IParent
{
public virtual ISet<Child> Children { get; set; }
}
public class ParentB
{
public virtual ISet<Child> Children { get; set; }
}
public class Child
{
public virtual IParent Parent { get; set; }
}
The question now is how would you map such a relationship in NHibernate?