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!