如何在 NHibernate 中编写以下 SQL 查询
嘿 - 我正在努力弄清楚如何使用 NHibernate ICriteria (多条件?)来编写以下内容:(
这是一个查询,用于获取最后一天表中按受欢迎程度排序的名字列表)
select firstname,count(firstname) as occurances from registrants
where timestamp between DateAdd(day,-1, GetDate()) and getdate()
group by firstname
order by count(firstname) desc
另外,鉴于这只是表中的几列,不包括 ID,并且 NHibernate 需要 ID 作为其对象,那么“伪造”ID 以便我可以获得结果的最简单方法是什么?
Hey - I'm battling to figure out how to write the following using NHibernate ICriteria (Multi criteria?) for the following:
(It's a query to get a list of first names ordered by popularity in the table in the last day)
select firstname,count(firstname) as occurances from registrants
where timestamp between DateAdd(day,-1, GetDate()) and getdate()
group by firstname
order by count(firstname) desc
Also, given this is just a couple of columns from a table, excluding the ID, and NHibernate needs ID's for it's objects, what's the easiest way to "fake" an ID so I can just get the results?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用投影和变压器来做到这一点。这是一些背景信息 http://nhibernate.info/doc/nh/en /index.html#querycriteria-projection
您需要创建一个名为 FirstNameOccurance 的类,该类具有 2 个名为 FirstName 和 Occurances 的属性。
You need to use projections and a transformer to do this. Here's some background info http://nhibernate.info/doc/nh/en/index.html#querycriteria-projection
You'll need to create a class called FirstNameOccurance that has 2 properties called FirstName and Occurances.