0

I need to get a list of nodes, based on 2 rules, both related to a date field (myDate in this example).

I currently have the following, that only takes one of the 2 rules, which is checking if the date field is empty;

var results = root.Descendants("myDocType") 
    .Where(x => !x.GetProperty("myDate").HasValue)
    .OrderBy("myDate desc");

In the same Where clause, i need to check for:

  • The date is empty OR
  • The date is today or earlier (just the date, not the time of day)

So i basically need to add the last requirement to my Where clause. But how?

1 Answer 1

0

Found the solution:

var results = root.Descendants("myDocType")
   .Where(x => !x.GetProperty("myDate").HasValue 
             || x.GetPropertyValue<DateTime>("myDate") >= DateTime.Now.Date)
   .OrderBy("myDate desc");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.