I have the following query:
where !(tf.Shipped.HasValue == true || tf.Ordered.HasValue == true || tf.Processed.HasValue == true)
Note that Shipped, Ordered and Processed are all nullable Boolean fields.
What I am trying to do is to check that if Shipped or Ordered or Processed have a value of true, they should NOT be in the result.
In my case Ordered is true but I am still getting this records. Not sure what I am doing wrong.
You’re checking whether the nullable bools have a value.
If that value is
false,HasValuewill still be true.You probably want to write
Comparing nullable bools is the only case where one should write
== true.However, you probably should not be using nullable bools in the first place.
Unless you have a meaningful distinction between
nullandfalse, you should use regular bools instead and save yourself a lot of headache.