Tom, thanks for your effort. Indeed, your solution works, but not the
way I wanted it to work.
What I wanted to achieve was that I wanted to serialize "hourly rates"
as table-per-class-hierarcy strategy, meaning that you have one table,
say "Rates" which has additional column "type", which defines the type
of the rate ('hourly rate', 'nightly rate', etc).
Your solution (and mine as well, if you remove the overrides) works in
a way that it uses table-per-class strategy, where you get a table for
every "hourly type", meaning that you get a table for hourlyrates,
table for nightlyrates, and so on.
The override '.Override<Rate>(map =>
map.DiscriminateSubClassesOnColumn("RateType"))' defines that I want
to store all the entities deriving from "Rate" in a single table,
where a column named "RateType" defines the type of this entry (row).
And when you store it like that, you get into the problem with
deserialization. The selects are missing a where clause to limit the
"correct entity type". And the solution I found was to add additional
overrides
.Override<Employee>(map => map.HasMany(m =>
m.RegularRates).Where("RateType = 'HourlyRate'"))
.Override<Employee>(map => map.HasMany(m =>
m.NightlyRates).Where("RateType = 'NightlyRate'"))
which define that when querying for RegularRates, include a SQL where
condition on RateType = 'HourlyRate'. I'm sort of surprised that this
is necessary, because the "saving" part works as expected and loading
doesnt. :(
I also received answers on nhusers mailing list telling me that I need
to specify the WHERE condition. The new overrides are also reflected
in HBM files (of course) like so:
<set cascade="all" name="NightlyRates" where="RateType =
'NightlyRate'" mutable="true">
<key>
<column name="Employee_id" />
</key>
<one-to-many class="NHibernatCollections.Models.NightlyRate,
NHibernatCollections, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" />
</set>
Note the where attribute.
Anyway, thanks for your effort and help.
Regards,
Miha