I've a problem when I want to sort my result (latest first...) from a query using QyeryHandler and also using paging on the result. The result-collection is divided on each page in the paging with the latest created record on the last page. If I then use the Sort()-method on the collection, each page in the paging is just sorted... The last created record is still on the last page... but on top of that.
There is no overload for the QueryHandler.GetQueryResult()-method that takes sortorder-parameter.
EntryCollection entries = QueryHandler.GetQueryResult<Entry, EntryCollection>(q, EPiServer.Templates.RelatePlus.Utils.CacheTimeOut.Search, page, ucBlogEntries.PageSize, out totalItems);
Any ideas of how to sort the query-result and still keep the paging?
The idea with all of the Get-methods and also with the Query system in EPiServer Community is that you let the database to the sorting for you.
In the query case you will see that all of the Query objects will have a property called OrderBy. In case of ImageGallery it could look something like this:
ImageGalleryQuery imageGalleryQuery = new ImageGalleryQuery();imageGalleryQuery.LastUpdate = new DateTimeCriterion();imageGalleryQuery.OrderBy.Add(newCriterionSortOrder(imageGalleryQuery.LastUpdate,SortingDirection.Descending));
Note that you have to init the criterion that you want to sort on.
Best regards,Tom Stenius
It worked fine.