We would like to display one table in two classes with NHibernate. The display should be dynamically dependent on the column value.
Here is a simple example to make it clearer: We have a table called Person with the column identifiers, Name and Sex.

Data from this table should be displayed in either the Male class or the Female class, depending on the value of the Sex column.

In pseudo code:
create instance of Male with data from table Person where Person.Sex = 'm';
create instance of Female with data from table Person where Person.Sex = 'f';
The advantage is that we strictly typed domain models and can later avoid switch statements.
Is this possible with NHibernate, or do we need to first map the Person table to a flat Person class? Then after that we will have to use our own factory method, which takes a flat instance of Person and returns an instance of Female or Male. It would be nice if NHibernate (or another library) can handle this.
source
share