Inheritance mapping with concrete base class
Hi,
in my domain, i have the following entities:
public class User {
public virtual int Id { get; set; }
public virtual string Name { get; set; }
}
public class Employee : User {
public virtual int EmployeeNo { get; set; }
}
both Users and employees are stored in the same table. The EmployeeNo column is a nullable int.
How can i configure FluentNHibernate mappings to create an instance of User when the EmployeeNo column is null, and an instance of Employee when EmployeeNo is not null?
Using standard .hbm.xml mapping files, i achieved that purpose using the following configuration:
<id name="Id">
<type name="Assigned" />
</id>
<discriminator formula="case when EmployeeNo is not null then 'E' else 'U' end" type="String" />
<property name="Name" column="Name" />
<subclass name="Employee" discriminator-value="E">
<property name="EmployeeNo" />
</subclass>
Thank you
Riccardo
2 Posted by Riccardo Gregori on 04 Jun, 2010 07:46 PM
A part of the .hbm.xml file has been cut away...