Combined Property Discriminator

Suppose I have this ratio:

abstract class Base { int Id; int JoinedId; ... }
class Joined { int Id; int Discriminator; ... }
class Sub1 : Base { ... }
class Sub2 : Base { ... }

for the following tables:

table Base ( Id int, JoinedId int, ... )
table Joined ( Id int, Discriminator int, ... )

I would like to set up hierarchy-based inheritance matching for the Base, Sub1, Sub2 relationships, but using the Disciminator property from the Join class as a discriminator.

Here's a general idea for a mapping file:

<class name="Base" table="Base">
    <id name="Id"><generator class="identity"/></id>

    <discriminator /> <!-- ??? or <join> or <many-to-one>? -->

    <subclass name="Sub1" discriminator-value="1">...</subclass>
    <subclass name="Sub2" discriminator-value="2">...</subclass>
</class>

Is there a way to accomplish something like this with <discriminator>, <join>or <many-to-one>? NHiberante seems to suggest that the discriminator is a column on this table (which makes sense to me .. I know this is unorthodox).

Thank.

+1
source share
3 answers

Can't you use a discriminator formula with a subquery on Joined?

<discriminator formula="(select j.discriminator from Joined j where j.id = joinedid)">
+3

, , , , , Google, . , , Meriton. , ( , ), , , , . , , , - MyTable0_1., . select. . SQL, , ... ( , )

....WHERE client0_.Id=@p0 and (SELECT ClientTypes.ClientClassId FROM ClientTypes WHERE ClientTypes.TypeId = client0_.TypeId)='f04c03db-d469-4c01-83c5-5a19c0aea264'

, .

+2

: , .

, , .

0

All Articles