I've got the inheritance version working as well with an interface as the base and wanted to post it here for completion.
public interface IParent
{
IList<Child> children { get; set; }
void AddChild(Child child);
Int64 Id { get; set; }
Child GetChild();
}
public class Parent : IParent
{
public virtual IList<Child> children { get; set; }
public Parent()
{
children = new List<Child>();
}
public virtual void AddChild(Child child)
{
children.Add( new Child() );
}
public virtual Int64 Id { get; set; }
public virtual Child GetChild()
{
return children.First();
}
}
public class Parent2 : IParent
{
public virtual IList<Child> children { get; set; }
public Parent2()
{
children = new List<Child>();
}
public virtual void AddChild(Child child)
{
children.Add(new Child());
}
public virtual Int64 Id { get; set; }
public virtual Child GetChild()
{
return children.First();
}
}
public class Child
{
public virtual Int64 Id { get; private set; }
}
These are mapped with the following:
<class name="IParent" table="IParents">
<id name="Id" unsaved-value="0">
<column name="Id" sql-type="bigint" />
<generator class="hilo" />
</id>
<bag name="children" cascade="all">
<key column="ParentId" />
<one-to-many class="Child" />
</bag>
<joined-subclass name="Parent" table="Parents" >
<key column="ParentId" />
</joined-subclass>
<joined-subclass name="Parent2" table="Parents2" >
<key column="ParentId" />
</joined-subclass>
</class>
<class name="Child" table="Children">
<id name="Id" unsaved-value="0">
<column name="Id" sql-type="bigint" />
<generator class="hilo" />
</id>
</class>
This in turn creates the following tables:
IParents
Id bigint
Parents
ParentId bigint
Parents2
ParentId bigint
Children
Id bigint
ParentId bigint
The big 'gotcha' to be aware of here is that the Child object refers directly to the Id in the IParents table only. And each instance of the Parent or Parent2 object is bound to a joined call between IParents and either Parents or Parents2 depending on what derived object type you're actually working with.
I haven't tested this with a class with multiple interfaces yet but I need to test that as well.
The thing I don't like about the inheritance model is that I need to have a common interface/base class. I'm not sure why I'm opposed to that offhand, it just seems clunky.
I think I'm going to roll with the crosstable method for now and revisit this later if I have to.