This project is read-only.

N2.Find OrderBy not applied before paging

Apr 2, 2009 at 8:58 PM
I really don't think I'm doing something wrong -- but it looks like folks are making similar queries with no reported problems.  I have a query like so:

            return N2.Find.Items
             .Where.Parent.Eq(this)
             .And.Type.Eq(typeof(NewsPage))
             .OrderBy.Detail("Date").Desc
             .FirstResult(firstIndex)
             .MaxResults(MaxResults)
             .Select<NewsPage>();

However it appears that the OrderBy is been applied after the paging such that if  I specify a firstIndex of 0 and MaxResults of 5 -- I get the five oldest items sorted by Date within that group.  If I change the OrderBy to Asc it reverses the ordering for those 5 items, however they still the 5 oldest in the whole database.  If  I remove the FirstResult and MaxResults I get everything with the most recent first.  How do I keep the dates sorted and still apply the paging?
Apr 2, 2009 at 9:35 PM
Nevermind -- I see that .OrderBy.Detail() creates a sort expression that is applied to the List *after* the query.  Hence my results...  Not being an nHibernate wizard and not having the time to dig much further -- I assume there is a reason for this?  I realize that the Templates uses the Published property for news but I can conceive of other detail field values you may want to sort by and do paging on.
Apr 2, 2009 at 9:50 PM
Sorry. I must have thought it was too tough to implement reliably as a query (it requires a join).
Apr 2, 2009 at 9:57 PM
Right, I was trying to imagine how that would go...  Since my time is limited, I will attempt to dump everything into the Published property for now.  (All of our news was dumped out of an older system straight into the database  -- hence the "Date" field -- wish I had thought of it when I was doing the dumping originally...)