Castle/ Active Records:如何计算对象?

发布于 2024-07-09 09:20:00 字数 353 浏览 2 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

您的好友蓝忘机已上羡 2024-07-16 09:20:00

有很多方法可以做到这一点,最简单的是:

ActiveRecordMediator<Product>.Count(Expression.Gt("date", DateTime.Now))

或者你可以使用 CountQuery、HQL 等,还有很多替代方案。

更新:对于 NHibernate 2.0+,它是 Restrictions 而不是 Expression

我会将此类常见问题复制到 ActiveRecord wiki

There are many ways to do this, the simplest is:

ActiveRecordMediator<Product>.Count(Expression.Gt("date", DateTime.Now))

or your could use CountQuery, HQL, etc, there are many alternatives.

UPDATE: for NHibernate 2.0+ it's Restrictions instead of Expression.

I'll copy common questions like these to the ActiveRecord wiki.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文