NHibernate投影和“具有"条款 [英] NHibernate Projections and "Having" clause
问题描述
我正在使用NHibernate用标准API查询数据库.我的条件如下:
I'm using NHibernate to query my database with the criteria API. My criteria is below:
ICriteria c = Session.CreateCriteria(typeof(Transaction));
ProjectionList projections = Projections.ProjectionList();
projections.Add(Projections.Sum("Units"), "Units");
projections.Add(Projections.GroupProperty("Account"), "Account");
projections.Add(Projections.GroupProperty("Security"), "Security");
c.SetProjection(projections);
这工作正常,但是我想要的是一种能够将查询限制为仅在"Units"属性> 0时才返回的方法.在NHibernate中找不到能够做到这一点的方法.是否有人有任何想法,还是我使用HQL的唯一选择?
This is working fine, but what I would like is a way to be able to limit the query to only return when the "Units" property is > 0. In SQL I would simply us a Having Units > 0
clause however I haven't been able to find a way to do this in NHibernate. Does anyone have any ideas or is my only option to use HQL?
推荐答案
您可以从Criteria对象访问ProjectionCriteria.
You can access the ProjectionCriteria from the Criteria object.
...
c.SetProjection(projections)
.ProjectionCriteria
.Add(Restrictions.Ge("Units", 0));
该解决方案当前不起作用,但是它应该在NHibernate 2.1.0中起作用
This solution doesn't currently work, however it should work in NHibernate 2.1.0
这篇关于NHibernate投影和“具有"条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!