我有一个ICriteria
从超类返回属性的Animal
。现在我想在结果中包含来自子类的几个属性,Bird
. 对于其他子类,这些属性应该返回null
. 我正在使用每个子类的表继承。有没有办法在不添加大量的情况下做到这一点DetachedCriteria
?NHibernate 已经在子类表上留下了连接;有没有办法从这些连接中投射价值?
更新:我需要能够对子类属性进行排序和过滤,并且整个查询需要支持分页。
这是我的模型:
public abstract class Animal
{
public long Id { get; set; }
public string Name { get; set; }
}
public class Cat : Animal
{
public int WhiskerCount { get; set; }
}
public class Bird : Animal
{
public long WingSpan { get; set; }
}
给定下表:
Animal:
Id | Name
----+--------------
1 | Sylvester
2 | Tweety
3 | Maru
4 | Big Bird
Cat:
Id | WhiskerCount
----+--------------
1 | 6
3 | 12
Bird:
Id | Wingspan
----+--------------
2 | 0.5
4 | 10
我想要以下结果集:
Id | Name | Wingspan
----+------------+-------------
1 | Sylvester | <null>
2 | Tweety | 0.5
3 | Maru | <null>
4 | Big Bird | 10