如何“撤消” Fluent NHibernate 中的投影?
我必须显示一些存储在关系数据库中的对象,我使用流畅的 NHibernate 来获取它们。
由于我需要分页,因此我必须获取所有对象的计数以及当前页面本身的对象。
这两个目的的 ICriteria 在某种程度上非常相似 - 对于计数我最后添加 .SetProjection(Projections.RowCount()) 对于当前的对象列表,我添加 SetFirstResult、AddOrder 和 SetMaxResults
有什么方法可以撤消对标准的投影并重用结果本身的标准,或者我是否必须为此目的重建标准?
hibernate 论坛建议了一种不工作。
I have to display some objects which are stored in a relational database and I use fluent NHibernate to get them.
Since I need paging, I have to get both - the count of all objects, and the objects for the current page themselves.
The ICriteria for both purposes is very similar up to a point - for count i finally add
.SetProjection(Projections.RowCount())
and for current object list I add
SetFirstResult, AddOrder and SetMaxResults
Is there any way I could undo the projection on the criteria and reuse criteria for the results themselves, or do I have to reconstruct the criteria for that purpose?
hibernate forums suggests a way that does not work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会编写一个封装查询逻辑的方法,包括限制、分组等:
然后将请求发送到数据库:
要进一步优化它,您可以看看这个优秀的博客帖子,其中 Ayende Rahien 谈论 NHibernate Futures。
I would write a method encapsulating the query logic including restrictions, grouping, ...:
And then send requests to the database:
To further optimize this you could take a look at this excellent blog post in which Ayende Rahien talks about NHibernate Futures.