我有这个 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
...
}
...