LINQ query where boolean value is true or false
How can I compare a boolean value to both true and false in a LINQ query?
If hideCompleted is true, I want to show values where IsC开发者_如何学Goompleted is false If hideCompleted is false, I want to show values where IsCompleted is true or false
Example:
(t1.IsCompleted ?? false == (hideCompleted == true ? false : (true || false)))
Just to be sure I understand you correctly, if hideCompleted is false, you don't care what the value of IsCompleted is? If so...
!(hideCompleted && t1.IsCompleted)
Build your query based on hideCompleted being true, similar to this approach:
var query = dc.SomeTable;
if (hideCompleted)
{
query = query.Where(t1 => !t1.IsCompleted);
}
This way when hideCompleted is true you filter for t1.IsCompleted being false. When hideCompleted is false your original query will grab all results regardless of the value of t1.IsCompleted.
you can use this condition
where (hideCompleted==true && t1.IsCompleted==false) || (hideCompleted==false)
加载中,请稍侯......
精彩评论