Hi!
I'm using most of the default configuration, but I overrode one entity
to be persisted using table-per-class-hierarchy concept.
I have an abstract base class AmountInfo and then have several other
derived classes, which add no other information to this base class.
They are mapped like so on an entity:
public class Employee : EntityBase
{
public virtual ISet<HourlyRate> HourlyRates { get; set;
}
where HourlyRate is defined like
public class HourlyRate : AmountInfo
{}
The configuration I'm using is:
var mapping = AutoMap.AssemblyOf<EntityBase>(new
CustomMappingConfiguration())
.IncludeBase<AmountInfo>()
.Override<AmountInfo>(map => {
map.DiscriminateSubClassesOnColumn("type");
map.SubClass<HourlyRate>("HourlyRate");
map.SubClass<EventHourlyRate>("EventHourlyRate");
map.SubClass<ExternalHourlyRate>("ExternalHourlyRate");
map.SubClass<SchoolHourlyRate>("SchoolHourlyRate");
map.SubClass<IndividualHourlyRate>("IndividualHourlyRate");
map.SubClass<OpenClassTicketPrice>("OpenClassTicketPrice");
map.SubClass<TwoPackagePrice>("TwoPackagePrice");
map.SubClass<ThreePackagePrice>("ThreePackagePrice");
})
.Override<AmountInfo>(map => map.LazyLoad())
.Override<HourlyRate>(map => map.LazyLoad())
.Override<ExternalHourlyRate>(map => map.LazyLoad())
.Override<EventHourlyRate>(map => map.LazyLoad())
.Override<SchoolHourlyRate>(map => map.LazyLoad())
.Override<IndividualHourlyRate>(map => map.LazyLoad())
}
I have ommited other parts of the configuration for brevity.
Now this seems to work for **saving** entities, but not for loading.
When loading, NHibernate does not add where clause to filter elements
based on "type" column. The generated XML fragment looks like:
<set cascade="all" name="HourlyRates" mutable="true">
<key>
<column name="Employee_id" />
</key>
<one-to-many class="Bbis.Core.Models.HourlyRate, Bbis.Core,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</set>
So when loading items, I get the following exception:
NHibernate.WrongClassException: Object with id: 6565 was not of the
specified subclass: Bbis.Core.Models.EventHourlyRate (loading object
was of wrong class [Bbis.Core.Models.HourlyRate]) because it loads all
of the items in the AmountInfo table and does not filter the contents
on the type column.
How can I approach this?
Thanks,
Miha.
--
You received this message because you are subscribed to the Google Groups
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/fluent-nhibernate?hl=en.