Is there any way to get NHibernate to let me store multiple ChildObjects in the ChildObjectTable but refer them back to different ParentObjects? Or do I have to create a separate ChildObject class/table for each ParentObject type?
I’ve boiled this down to the following, I’m trying to map these objects:
public class ParentObjectA { public virtual Int64 Id { get; private set; } public virtual IDictionary<int, ChildObject> Children { get; private set; } } public class ParentObjectB { public virtual Int64 Id { get; private set; } public virtual IDictionary<int, ChildObject> Children { get; private set; } } public class ChildObject { public virtual Int64 Id { get; private set; } }
into the following table structure:
ParentObjectTableA Id bigint ParentObjectTableB Id bigint ChildObjectTable Id bigint ParentId bigint ParentQualifier varchar(50)
The following maps seem to work from an object perspective. I’m not overly keen on the idea of using crosstables, but I think this might be cleaner than trying to deal with inheritance. I’m going to take a look at that option as well and I’ll post my findings here for the sake of completion. Comments welcome.
Mapping of ParentObjectA
Mapping of ParentObjectB
These generate the following cross tables: