I am having issues finding good documentation for the problem I am having. I am reconstructing a portion of an enterprise solution and swapping over the NHibernate for our ORM. I have 3 tables which I want to all inherit from each other.
MasterAccount : Account : InvBilling
**MasterAccount**
id_MasterAccount
**Account**
id_Account
id_MasterAccount
id_InvBilling
**InvBilling**
id_InvBilling
id_MasterAccount
For each row in MasterAccount there exists a row in Account where the Id_MasterAccount columns are equal and the IsMaster column is 1. However, there are also other records in the Account table which also have their id_MasterAccounts equal to associate with their parent account. Finally, every record in the Account table has a record in the InvBilling table.
I am having lots of issues setting up their mappings. Any help with how to set this up?
I need to somehow tell MasterAccount which Account record it should associate itself to as well as the column it should use.
Edit: Here is what I have so far:
public class MasterAccountEntity : AccountEntity{
protected virtual int MAId {get;set;}
}
public class AccountEntity : InvBillingEntity{
protected virtual int AId {get;set;}
public virtual MasterAccountEntity MA {get;set;}
public virtual InvBillingEntity IB {get;set;}
public virtual bool IsMaster {get;set;}
}
public class InvBilling{
protected virtual int IBId {get;set;}
public MasterAccountEntity MA {get;set;}
}
Then for my mappings(somewhat lost on how to show the inheritance):
public class FluentHibernateMap : SubclassMap<MasterAccountEntity>{
Table("MasterAccount");
Map(x => x.MAId).Column("id_MasterAccount");
}
public class FluentHibernateMap : SubclassMap<AccountEntity>{
Table("Account");
Map(x => x.AId).Column("id_Account");
Map(x => x.IsMaster).Column("isMaster");
References(x => x.MA).Column("id_MasterAccount").Not.Nullable().Cascade.None();
References(x => x.IB).Column("id_InvBilling").Not.Nullable().Cascade.None();
}
public class FluentHibernateMap : ClassMap<InvBillingEntity>{
Table("InvBilling");
Id(x => x.IBId).Column("id_InvBilling");
References(x => x.MA).Column("id_MasterAccount").Not.Nullable().Cascade.None();
}
So MasterAccount needs to inherit the record from Account where IsMaster is true, and then inherit the record in InvBilling that cooresponds to the InvBillingId in Account.