You have an order-of-operations issue. OR
(||
) is evaluated before the conditional ternary operator. You need to surround the two OR
operations with parentheses:
where i.IsDeleted == false &&
(
(i.ResultOther == true ? "ResultOther".ToLower().Contains(searchValue) : i.IncidentID.ToString().Contains(searchValue))
|| (i.BodyPartHead == true ? "BodyPartHead".ToLower().Contains(searchValue) : i.IncidentID.ToString().Contains(searchValue))
)
You original code is equivalent to:
where i.IsDeleted == false &&
(
i.ResultOther == true
? "ResultOther".ToLower().Contains(searchValue)
: (i.IncidentID.ToString().Contains(searchValue)) || (i.BodyPartHead == true)
? "BodyPartHead".ToLower().Contains(searchValue)
: i.IncidentID.ToString().Contains(searchValue))
)
(you can also get rid of == true
and use !
instead of == false
, but those don't change the results and are just cosmetic changes)