Linq where clause with multiple conditions and null check
Posted
by SocialAddict
on Stack Overflow
See other posts from Stack Overflow
or by SocialAddict
Published on 2010-03-17T16:43:45Z
Indexed on
2010/03/17
16:51 UTC
Read the original article
Hit count: 1064
LINQ
|where-clause
I'm trying to check if a date is not null in linq and if it isn't check its a past 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?
© Stack Overflow or respective owner