I just thought that I would share the way I was able to achieve this using Fluent NHibernate and not hbm files.
This method is a bit hacky, but the hacks are isolated and easily removed as soon as Fluent NH gets proper support for the Union subclass.
To use your example, the context of my scenario is as follows: the Employee class is in one project with the AccountManager property specified as an interface, because a specific AccountManager is in another project that we do not want to create a dependency on.
First, I create a helper class that does most of the Employee display and looks like this.
public abstract class EmployeeMapperBase { protected abstract Type GetAccountManagerType(); public void DoMapping(ClassMap<Employee> classMap) { classMap.Id(x => x.Id); classMap.Maps(..... etc.... classMap.References(x => x.AccountManager) .Class(GetAccountManagerType()); } }
Then, in the project with the specific AccountManager class, I will complete the mapping:
public class EmployeeClassMap : ClassMap<Employee> { public EmployeeClassMap { new ConcreteEmployeeMapper().DoMapping(this); } private class ConcreteEmployeeMapper : EmployeeMapperBase { public override Type GetAccountManagerType() { return typeof(DefaultAccountManager); } } }
source share