Castle/ Active Records:如何计算对象?
我正在尝试使用 NHibernate 上的 Castle 执行一个简单的“从日期 > xxx 的产品中选择计数(*)”。
如果我直接使用 NHibernate,我可以重用 这个问题回答了,但不幸的是我没有看到从 Castle Records 访问当前 NHibernate 会话的简单方法。
我显然不想检索所有对象并在 C# 端执行计数;)。 我只需要知道有多少个对象。
有任何想法吗?
I'm trying to do a simple "Select Count(*) from PRODUCTS where date > xxx" with Castle on NHibernate.
If I was directly using NHibernate, I could reuse this question answers but unfortunately I see no easy way to access the Current NHibernate session from Castle Records.
I obviously don't want to retrieve all my objects and do a Count on the C# side ;). I only need to know how many objects there are.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多方法可以做到这一点,最简单的是:
或者你可以使用 CountQuery、HQL 等,还有很多替代方案。
更新:对于 NHibernate 2.0+,它是
Restrictions
而不是Expression
。我会将此类常见问题复制到 ActiveRecord wiki。
There are many ways to do this, the simplest is:
or your could use CountQuery, HQL, etc, there are many alternatives.
UPDATE: for NHibernate 2.0+ it's
Restrictions
instead ofExpression
.I'll copy common questions like these to the ActiveRecord wiki.