Copied to clipboard

Flag this post as spam?

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


  • John Churchley 27 posts 172 karma points
    May 05, 2014 @ 23:14
    John Churchley
    0

    OrderBy() followed by First()

    I have a nodes of alias seminars with a property of seminarDate. I'm attempting to order these nodes under the parent node of type Schedule and then display only the next seminar coming up (ignoring any dates which has past). See attempt below.

    var latestSeminar = @Model.Content.AncestorOrSelf(1).DescendantOrSelf("Schedule").Children.OrderBy("seminarDate").First(x => x.seminarDate > DateTime.Now).GetPropertyValue("seminarDate");
    
  • Amir Khan 1287 posts 2744 karma points
    May 05, 2014 @ 23:25
    Amir Khan
    0

    If the upcoming one is always the first one, you could just use Take(1).

    -Amir

  • John Churchley 272 posts 1258 karma points c-trib
    May 06, 2014 @ 01:09
    John Churchley
    0

    Hi Amir, it won't always be the first as the list contains all seminar which have happen. I'm sure there is a way to create a dynamic list and then filter by property just don't no how yet!?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    May 06, 2014 @ 09:21
    Jeavon Leopold
    0

    Hi John,

    You are very close already!

    var latestSeminar = Model.Content.AncestorOrSelf(1).DescendantOrSelf("Schedule").Children.OrderBy("seminarDate").FirstOrDefault(x => x.GetPropertyValue<DateTime>("seminarDate") > DateTime.Now);
    
  • John Churchley 272 posts 1258 karma points c-trib
    May 06, 2014 @ 20:00
    John Churchley
    0

    Thank You

Please Sign in or register to post replies

Write your reply to:

Draft