PredicateBuilder is still true even after adding explicit false statement
-
16-06-2021 - |
Question
I have the following statement.
var search = PredicateBuilder.True<SomeType>();
search.And(f => false);
// Still the "search" variable value is: {f => true}.
At first, I was trying an expression; nothing succeeded, so I tried this "false" instead. No matter what I did, it's still the same. What is happening?
La solution
PredicateBuilder
methods don't mutate the expression (they couldn't, as expression trees are immutable) - you need to use the return value:
var search = PredicateBuilder.True<SomeType>();
search = search.And(f => false);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow