I am using the following fluent mapping for two classes :
1.Application class :
public ThirdPartyAppMap()
{
Schema("Data");
Id(x => x.ThirdPartyAppId).GeneratedBy.Identity();
Map(x => x.AppName);
Map(x => x.CreationTime);
Map(x => x.Enabled);
References(x => x.ThirdPartyCustomer, "ThirdPartyCustomerId").Class(typeof(ThirdPartyCustomer));
HasMany(x => x.ThirdPartyUsersIds).Table("Data.ThirdPartyUser").KeyColumn("ThirdPartyAppId").Element("UserId").AsBag();
}
Which is a simple application in my core domain
and a sub class of it : ApplicationExt mapping :
public ThirdPartyAppProxExtMap()
{
Table("Data.ThirdPartyApp");
KeyColumn("ThirdPartyAppId");
this.HasManyIds(x => x.DeviceToAppRelIds, "Data.ThirdPartyDeviceToAppRel", "AppId", "ThirdPartyDeviceToAppRelId");
}
Which is mapped to the same table but adds a hasmany property which is a list of ids . This class is in a higher level domain which is based on the core domain , the core domain does not need to know the rels of the application class while the higher domain does.
The mapping works fine but I encounter an exception while working with a NH session object :
When I call
Session.Refresh(BaseAppObject)
I receive the following exception :
Unable to cast object of type 'RedPill.Applicative.Module.CM.Domain.ThirdPartyApp' to type 'RedPill.Applicative.Module.PI.Domain.ThirdPartyAppProxExt'.
It throws invalidcastexception because it tried to assign data to the extended type property which does not exists on the BaseAppObject , only on the ExtAppObject . Looking at the profiler the sesion object tried to fetch ExtApplicationObject instead of BaseApplicationObject. So basically , I did Session.Get() , recieved BaseAppObject which works fine , but when I am trying to refresh it using Session.Refresh() it tries to Fetch ExtApplicationObject and when NH tries to build the object from the selection it throws invalid cast exception.
Any help on this one ?
Regards ,
James