I have two tables which share common fields. Rather than re-map all of these I would like to have a base class with the common fields. For POCO this is simple:
class Base
{
public string commonField {get;set;}
}
class Derived : Base
{
public string specificField {get;set;}
}
class OtherDerived : Base
{
public string specificOtherField {get;set;}
}
Note that there is no such thing as a table for “base”. It just holds lots of common fields shared among several tables. Yes, I know this is not well normalized, but it’s what I have to work with.
My question is – is there a way to implement this in fluent nHibernate without having to duplicate the code that maps those common properties?
You can inherit from
ClassMapto do this. I would do something like the following:Notice the
Polymorphism.Explicit();above. In your case I think you are going to want this.http://www.nhforge.org/doc/nh/en/#mapping-declaration-class