Copied to clipboard

Flag this post as spam?

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


  • Simon 12 posts 43 karma points
    Apr 29, 2013 @ 13:06
    Simon
    0

    Collections: OrderBy date property

    Hi Guys,

    Has anyone ever tried to order a collection by a date property that may or may not have a value? If I populate all the items with dates then there are no problems. If I set the date to null on some and there are at least two others with date values then  that is fine also. The error occurs if I have one or less date properties set in the collection.

    Any ideas?

    Simon

  • Charles Afford 1163 posts 1709 karma points
    Apr 29, 2013 @ 21:29
    Charles Afford
    0

    When you say a collection, what type is this?  Ienum, List?  When you say items in the collection what types are these?  I dont understand when the error is occuring :).  Charlie.

  • Simon 12 posts 43 karma points
    Apr 30, 2013 @ 01:17
    Simon
    0

    Yeah, sorry I should have really provided more info :)

    For example, I have a page which lists a node collection of a particular along with their properties. One of those properties is of date type, which may or may not contain a value, but would like to order by it as best as I can

  • Mike Chambers 635 posts 1252 karma points c-trib
    Apr 30, 2013 @ 10:14
    Mike Chambers
    0

    I had to revert back to linq to get around this..

    DynamicNode[] nodelist = homePageNode.DescendantsOrSelf().Items
                                    .Where(x => x.GetPropertyValue("hideInNavigation") != "1"
                                        && x.HasAccess
                                        && x.Level <= level
                                        && (DateTime.Parse(x.HasValue("ExpireDate", x.GetPropertyValue("fidusCMSExpireDate"), DateTime.Now.AddHours(1).ToString()).ToString()) > DateTime.Now)
                                        && (DateTime.Parse(x.HasValue("ReleaseDate", x.GetPropertyValue("fidusCMSReleaseDate"), DateTime.Now.AddHours(-1).ToString()).ToString()) < DateTime.Now)).ToArray();
    
  • Simon 12 posts 43 karma points
    Apr 30, 2013 @ 10:58
    Simon
    0

    Thanks for the reply Mike.

    How could this approach be used with the OrderBy() method though instead of inside a Where()?

    Simon 

  • Mike Chambers 635 posts 1252 karma points c-trib
    Apr 30, 2013 @ 11:03
    Mike Chambers
    0

    maybe something like 

    OrderBy(x => x.HasValue("ExpireDate", x.ExpireDate,DateTime.Now))

     

    eg if no date then use time now.. or your choice of how to deal with no set date.

  • Simon 12 posts 43 karma points
    Apr 30, 2013 @ 11:40
    Simon
    0

    Hmm thought you might say that ... trouble is I'm working within a Razor macro and am I right in thinking you cannot use the predicate within the OrderBy() and must provide a string representation? Correct me if I'm wrong; I'm still pretty new to the Umbraco world! 

  • Charles Afford 1163 posts 1709 karma points
    May 02, 2013 @ 21:11
    Charles Afford
    0

    i think thats correct but dont work with macros, will read up on them :)

Please Sign in or register to post replies

Write your reply to:

Draft