I'm trying to check if a date is null in linq and if it isn't check its a future date.
QuestionnaireRepo.FindAll(q => !q.ExpiredDate.HasValue || q.ExpiredDate >DateTime.Now).OrderByDescending(order => order.CreatedDate);
I need the second check to only apply if the first is true. I am using a single repository pattern and FindAll accepted a where clause
ANy ideas? There are lots of similar questions on here but not that give the answer, I'm very new to Linq as you may of guessed :)
Edit: I get the results I require now but it will be checking the > conditional on null values in some cases. Is this not a bad thing?
Won't this work?
QuestionnaireRepo.FindAll(
q => (q.ExpiredDate == null) || (q.ExpiredDate > DateTime.Now));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With