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

Issue with Assert.Throws Exception in NUnit testing

c# unit-testing exception-handling nunit integration-testing

I am trying out NUnit, Unit Testing and Integration testing for the first time. I have been reading up and doing lots of online courses. As I'm sure you know very well it's something knowing theory...

Is there any way to hide "-" (Delete) button while editing UITableView

iphone cocoa

On my iphone app, I have a UITableView in edit mode, where user is allowed only to reorder the rows no delete permission is given.