Copied to clipboard

Flag this post as spam?

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


  • Amir Khan 1287 posts 2744 karma points
    May 20, 2013 @ 15:54
    Amir Khan
    0

    Take combined with OrderBy isn't returning expected results

    Hi, I have this loop thats supposed to print the latest 3 blog posts and sort them by the postDate (datepicker) property. Whats happening is that if there are more than 3, it doesn't actually show the most recent one, if I change the Take(3) to Take(4) it shows the latest 4 items in the correct order. Any idea why this is happening?

     

    foreach (var node in nodes.Take(3).OrderBy("postDate desc"))

    -Amir

  • Ulrich Wagner Gade Ebsen 127 posts 277 karma points
    May 20, 2013 @ 15:57
    Ulrich Wagner Gade Ebsen
    101

    Hi,

    Try to change the order.. ie. "nodes.OrderBy("postDate desc").Take(3)" .. ;)

    /ulrich

  • Amir Khan 1287 posts 2744 karma points
    May 20, 2013 @ 16:00
    Amir Khan
    0

    Ulrich, you are the man! Thank you!

    -Amir

Please Sign in or register to post replies

Write your reply to:

Draft