Using Nhibernate subclass, we can easily bring the inheritance into model.In the real time business object models are making use of OOPS concepts and Lets see how we can map the object to data structure of SQL.
Subclass and discriminator really help us to avoid one to one mapping of object to SQL table.See below the object we want to map using Nhibernate,
See also the data structure we need to map,
Write Nhibernate mapping file for making use of the discriminator property,which specifies the type and base type, In our case discriminator column is PersonTypeId. Don’t forget to use not null property for the discriminator column while mapping.
See the mapping file below,
This makes Employee and Student as type can be selectable with distinguished properties.