Trick question about mapping inheritance:

I have the following classes:

class Base
abstract class AbstractDerived : Base
class ConcreteDerivedA : AbstractDerived
class ConcreteDerivedB : AbstractDerived
...
class ConcreteDerivedN : AbstractDerived

I want to map them with the table-per-hierarchy strategy (e.g., single
table for all).

There is a int property in Base which can be used as a discriminator,
but the mapping is tricky because Base has two possible values:
Values 1 and 2 map to Base.
Value 3 maps to ConcreteDerivedA.
Value 4 maps to ConcreteDerivedB.

If there was some kind of discriminator-value-list attribute, I could
use it. But it seems that only scalars can be used.

I ended up doing something like:

<class name="Base" discriminator-value="-1">
  <discriminator formula="case when TypeCode in (3,4) then TypeCode
else -1" type="Int32"/>
  ...
</class>
<subclass name="ConcreteDerivedA" extends="Base" discriminator-
value="3">
  <property name="XFromAbstractDerived".../>
  ...
</subclass>
<subclass name="ConcreteDerivedB" extends="Base" discriminator-
value="4">
  <property name="XFromAbstractDerived".../>
  ...
</subclass>

But this leaves out the AbstractDerived class which I want mapped. I
also need to repeat its properties in all the concrete derived
classes, which is pretty ugly.

Any ideas?

TIA,
Roy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" 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/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to