2

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?

Ron
  • 245
  • 3
  • 9

1 Answers1

1

Ayende has a sample NHibernate Blog model. And Tag entity has a reference to its parent with property called Entity. Type of the Entity is object, and it is mapped either to be a Post or a Blog. Its might be what you are looking for.

All files in the model here Tag source and mapping

Sly
  • 15,046
  • 12
  • 60
  • 89