views:

559

answers:

1

Hi,

I'm trying to get say the top 10 scores for the users of my application. I'm usually using something along the lines of

User.SlicedFindAll(0, 10, 
NHibernate.Expression.Expression.Eq("IsActive", true), 
NHibernate.Expression.Order.Desc("Score")

which is usually used for pagination purposes. However, I don't want to add any constraint (WHERE clause) to my request. Hence I tried something along the lines of

User.SlicedFindAll(0, 10, 
null, 
NHibernate.Expression.Order.Desc("Score")

but this throws a NullReferenceException. Any pointers? (I guess SlicedFindAll is not a good choice)

Google didn't help on that one.

+3  A: 

You can use this overload:

public static T[] SlicedFindAll(int firstResult, int maxResults, NHibernate.Expression.Order[] orders, params NHibernate.Expression.ICriterion[] criteria)

in your case it would be:

User.SlicedFindAll(0, 10, new[] {Order.Desc("Score")})
Mauricio Scheffer
Thanks, that's what I ended doing even if I feel this is probably not optimal :)
Luk
SlicedFindAll reference docs: http://api.castleproject.org/html/Overload_Castle_ActiveRecord_ActiveRecordMediator_1_SlicedFindAll.htm
Mauricio Scheffer