NHibernate QueryOver with MaxResult, Group By 和 Order By [英] NHibernate QueryOver with MaxResult, Group By and Order By
本文介绍了NHibernate QueryOver with MaxResult, Group By 和 Order By的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将 SQL 查询转换为 NHibernate QueryOver 语法,但我不明白如何按计数投影进行排序.
I'm trying to convert a SQL query to NHibernate QueryOver syntax, but I don't understand how to sort by the count projection.
这是 SQL 查询的样子:
This is what the SQL Query looks like:
select top 10 v.intVoteUserID, COUNT(v.intVoteUserID)
from Group_MessageVotes v
where v.dtmVote > :date
group by v.intVoteUserID
order by COUNT(v.intVoteUserID) desc
有什么想法吗?
推荐答案
您可以简单地重复 OrderBy 子句中的投影.
You can simply repeat the projection in the OrderBy-clause.
以下查询将为您提供一个 IList
,其中每个项目的第一个元素是 id,第二个元素是计数.
The following query will give you an IList<object[]>
where the first element of each item is the id and the second is the count.
var result = session.QueryOver<GroupMessageVotes>()
.Select(
Projections.Group<GroupMessageVotes>(e => e.intVoteUserID),
Projections.Count<GroupMessageVotes>(e => e.intVoteUserID)
)
.OrderBy(Projections.Count<GroupMessageVotes>(e => e.intVoteUserID)).Desc
.Take(10)
.List<object[]>();
这篇关于NHibernate QueryOver with MaxResult, Group By 和 Order By的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文