Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Josip 187 posts 652 karma points c-trib
    Sep 14, 2018 @ 20:53
    Josip
    0

    strongly typed syntax warning

    Hello everyone, could someone tell me how could i fix this?

    http://prntscr.com/kuj29y

  • Marc Goodson 1451 posts 9716 karma points MVP 5x c-trib
    Sep 14, 2018 @ 22:30
    Marc Goodson
    100

    Hi Josip

    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:

    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

  • Josip 187 posts 652 karma points c-trib
    Sep 15, 2018 @ 15:54
    Josip
    0

    Thanks a lot Marc, i will check this out :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies