QueryOver operator to select N rows with a descending DateTime order

I am trying to write a QueryOver statement to select N rows in descending time order.

session.QueryOver<T>().Take(10).OrderBy(x=>x.DateInserted);

Unfortunately, this does not work at all. Is there any way to figure this out?

+5
source share
1 answer

You did not indicate whether you want to be in ascending or descending order in the request, so try this:

session.QueryOver<MyClass>()
       .OrderBy(x => x.DateInserted).Desc
       .Take(10).List();

At the end, you must call the List to get a collection containing the results, and remember to replace the generic type T with your class name.

+9
source

All Articles