用于以下类映射:
<class name="Person" table="Person" discriminator-value="null">
<id name="ID" column="ID" >
<generator class="identity"/>
</id>
<discriminator column="MasterId" />
<property name="LongName" column="LONGNAME" />
<property name="ShortName" column="SHORTNAME" />
// other stuff here ...
<subclass name="PersonHistory" discriminator-value="not null">
<property name="MasterId" />
</subclass>
</class>
执行时:
var query =
from lac in session.Query<Person>()
orderby lac.LongName
select lac;
return query.ToList();
我从 Person 表中获取所有条目,两者都将MasterId设置为null而不是null。有没有办法让NHibernate只获取MasterId = null的实体?
答案 0 :(得分:1)
如何在您的案例中使用discriminator公式?
<discriminator formula="case when MasterId is null then 0 else 1 end" />
然后为类设置了discriminator属性值:
答案 1 :(得分:1)
为了实现我想要的,我创建了基类+两个子类。这是配置:
discriminator-value 的子类:
<subclass name="People" discriminator-value="null">
</subclass>
<subclass name="PeopleHistory" discriminator-value="not null">
<property name="MasterRowId" />
</subclass>
基础类中的鉴别器:
<discriminator column="MasterRowId" />