I have an entity like:
public class Employee
{
public int ID { get; set; }
public IAccountManager AccountManager { get; set; }
...
}
I also have a mapping defined for “DefaultAccountManager” – a concrete implementation of IAccountManager. When mapping the above “Employee” entity, how do I tell NHibernate to persist/load the AccountManager property using the mapping defined in “DefaultAccountManager”?
Edit:
Actually if I could setup a mapping for IAccountManager so that NHibernate could just infer which implementer to load/persist that would be even better. I’d rather not have to break polymorphism by forcing all implementers to use the same mapping.
I did find an answer to this one. I’m a little hazy on the details, as it was a few months ago, but the following was the jist of the solution:
Union-subclasses would look something like this:
Note the attribute “name” on union-subclass. This should be unique for (and match) each implementation of IAccountManager.
Also, the ID, instead of being unique to each table, will be unique to all IAccountManagers (by leveraging hilo).
When NHibernate sees an IAccountManager entity, it will use the instance’s concrete type and the union-subclass definitions to figure out the correct table.
Hope this helps!