I'm trying to use NHibernate to map a table per subclass inheritance structure that looks something like this:
public class BaseClass
{
public virtual IColllection<BaseClassCollection> Collection { get; set; }
}
public class ChildClass : BaseClass
{
public new virtual ICollection<ChildClassCollection> Collection { get; set; }
}
I get the following error when I try to get a ChildClass from the session:
"Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag1[BaseClassCollection]' to type 'System.Collections.Generic.ICollection
1[ChildClassCollection]'."
Here's my mapping file:
<class name="BaseClass" table="BaseClassTable">
<bag name="Collection">
<key>
<column name="BaseClassCollectionId" />
</key>
<one-to-many class="BaseClassCollection" />
</bag>
<joined-subclass name="ChildClass" table="ChildClassTable">
<key>
<column name="BaseClassId" />
</key>
<bag name="Collection">
<key>
<column name="ChildClassCollectionId" />
</key>
<one-to-many class="ChildClassCollection" />
</bag>
</class>
I need some way of overriding the type of the Collection property in the base class when I map the child class. Is this possible with NHibernate?