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.
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.
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
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!
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
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.
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
I had to revert back to linq to get around this..
Thanks for the reply Mike.
How could this approach be used with the OrderBy() method though instead of inside a Where()?
Simon
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.
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!
i think thats correct but dont work with macros, will read up on them :)
is working on a reply...