QueryOver statement for selecting N rows with descending DateTime order
Asked Answered
B

1

10

I am trying to write QueryOver statement for selecting N rows in the descending time order.

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

Unfortunately this is not at all working. Is there any way to sort it out?

Brierwood answered 23/6, 2012 at 18:35 Comment(0)
H
19

You haven't specified if you want ascending or descending order in your query, so try doing like this:

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

At the end you have to call List to get a collection containing the results, and don't forget to replace the generic type T by your class name.

Hornmad answered 23/6, 2012 at 19:39 Comment(2)
Maybe .Desc() ? (method)Consumable
@Consumable No, it is a property.Korey

© 2022 - 2024 — McMap. All rights reserved.