Castle/ Active Records: How do you count objects?

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?


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.

Need Your Help

Quartz CronTrigger executing jobs on wrong date/time

java quartz-scheduler cronexpression

I am using following cron expression to execute a job on every Friday at specified time of day (in sample below it's 1:13 PM).

Why user data is not being stored into mysql using fb login?

javascript mysql facebook facebook-login

I am using facebook javascript SDK to register and login the user to my site.Login is working fine.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.