You can pass a lambda into either an OrderBy or an OrderByDescending query...
var selection = Model.Content.Site().FirstChild("news").Children("newsItem").Where(x => x.IsVisible()).OrderByDescending(x=>x.CreateDate).Take(2);
.. but be careful as this approach would first get all the News Articles into memory before ordering by date, and then returning only 2 items, so could be un-performant with hundreds of articles, you'd certainly want to cache the output in a macro, so it's not continually making this query...
....There was a talk by Dave Woestenborghs, called the need for speed, with slides detailing your exact scenario and the relative speeds of the different approaches:
strongly typed syntax warning
Hello everyone, could someone tell me how could i fix this?
http://prntscr.com/kuj29y
Hi Josip
You can pass a lambda into either an OrderBy or an OrderByDescending query...
.. but be careful as this approach would first get all the News Articles into memory before ordering by date, and then returning only 2 items, so could be un-performant with hundreds of articles, you'd certainly want to cache the output in a macro, so it's not continually making this query...
....There was a talk by Dave Woestenborghs, called the need for speed, with slides detailing your exact scenario and the relative speeds of the different approaches:
https://www.slideshare.net/dawoe/the-need-for-speed-uk-fest
so you might find one of these approaches (see slide 55) XPath Navigator approach worth investigating if you have tons of News Articles.
regards
Marc
Thanks a lot Marc, i will check this out :)
is working on a reply...