对鉴别器值进行投影
本文关键字:投影 鉴别 | 更新日期: 2023-09-27 18:32:23
我有这个 NHibernate 映射
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class name="ParentClass" table="myclass" abstract="true" >
...
<discriminator column="mytype" type="string" />
...
<subclass name="SubClass1" discriminator-value="Type1" />
<subclass name="SubClass2" discriminator-value="Type2" />
</class>
</hibernate-mapping>
那么,当我过滤 ParentClass 对象时,我如何才能像 DAO 中的任何属性一样获得鉴别器值的投影?DAO 中的代码:
...
using (ISession session = NHibernateSession)
{
ICriteria criteria = session.CreateCriteria<ParentClass>("p")
...
criteria.SetProjection(Projections.ProjectionList()
.Projections.Property("p.Property1")
.Projections.??? // something to get discriminator-value from myclass.mytype column
...
}
...
这应该是"p.class"
的方式:
criteria.SetProjection(Projections.ProjectionList()
.Add(Projections.Property("p.Property1"))
.Add(Projections.Property("p.class"))
);
17.1.4.1. 别名和属性引用
Description Syntax Example
...
Discriminator of an entity {[aliasname].class} DISC as {item.class}
....