tags:

views:

191

answers:

1

I have a set of tables that look like the following:

Person - PersonID, FirstName, LastName, etc...
Family - FamilyID, etc...
Parent - PersonID, FamilyID, etc...
Child - PersonID, FamilyID, etc...
Contact- PersonID, etc...

My object hierarchy is organized as follows (using c#):

class Person
class Family
interface IFamilyMember

class Parent : Person, IFamilyMember
class Child : Person, IFamilyMember
class Contact : Person

Using Nhibernate - I am currently mapping each of the Person subclasses via joined-subclass as shown below (irrelevant fields are removed):

<!-- Parent -->
<joined-subclass name="Parent" table="Parent">
  <key column="PersonID" />
  <many-to-one name="Family" column="FamilyID" cascade="save-update" />
</joined-subclass>

<!-- Child -->
<joined-subclass name="Child" table="Child">
  <key column="PersonID" />
  <many-to-one name="Family" column="FamilyID" cascade="save-update" />
</joined-subclass>

<!-- Child -->
<joined-subclass name="Contact" table="Contact">
  <key column="PersonID" />
</joined-subclass>

The problem is that I would REALLY like to be able to execute queries against the IFamilyMember interface, and with the current mapping, NHibernate does not allow to execute an HQL query such as "From IFamilyMember". I would also like to be able to select by other criteria -- "From IFamilyMember m where m.Name.First = 'blah'. How would I map this set of classes such that I could select family members by name, etc... ? Do I have to modify my class hierarchy such that IFamilyMember contains the properties by which I wish to query (Name, etc...)?

Thanks for the help!

A: 

Why are Parent and Child different entities? In just the standard 'family' sense, each is just a Person - the Parent/Child is a relationship that is probably best modeled through a many-to-many relationship expressed in a 2nd table.

Harper Shelby
I tried to remove fields/properties irrelevant to the discussion. Parent and Child have additional fields which are not common between them and the other types which inherit from Person. These fields are numerous enough and specialized enough that do not think it would be good design for them to be a part of the Person entity.
Krazzy
Fair enough - that's why I asked, rather than assuming your design was wrong.
Harper Shelby