基于连接属性的区分符 [英] Discriminator based on joined property
问题描述
假设我有这种关系:
abstract class Base { int Id; int JoinedId; ... }
class Joined { int Id; int Discriminator; ... }
class Sub1 : Base { ... }
class Sub2 : Base { ... }
对于以下表格:
table Base ( Id int, JoinedId int, ... )
table Joined ( Id int, Discriminator int, ... )
我想为Base,Sub1,Sub2关系建立一个按层次结构的表继承映射,但要使用Joined类中的Disciminator属性作为鉴别符.
I would like to set up a table-per-hierarchy inheritance mapping for the Base, Sub1, Sub2 relationships, but using the Disciminator property from the Joined class as the discriminator.
以下是映射文件的基本概念:
Here's the general idea for the 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>
是否可以用<discriminator>
,<join>
或<many-to-one>
完成类似的操作? NHiberante似乎假设鉴别符是给定表上的一列(这对我来说很有意义.我知道这是非正统的).
Is there any way of accomplishing something like this with the <discriminator>
, <join>
, or <many-to-one>
? NHiberante seems to assume the discriminator is a column on the given table (which makes sense to me.. I know this is unorthodox).
谢谢.
推荐答案
不能在Joined
上使用带有子选择项的判别式吗?
Can't you use a discriminator-formula with a subselect on Joined
?
<discriminator formula="(select j.discriminator from Joined j where j.id = joinedid)">
这篇关于基于连接属性的区分符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!