Search code examples
c#linqboolean-logicboolean-expressionbooleanquery

Category isn't this unless property is false


As the title describes. I am stuck, an otherwise simple use of and, xor, or expressions in a LINQ statement.

from s in db.Items
where <Other boolean operations> &&
      s.Category.Contains("something") &&
      s.IsReviewed == false

Where I want the other boolean operations to filter the list down, and where the remainder of items should not be of the category "something" unless the IsReviewed bool is false.

An alternate way to express this is: I want items of any category to show, except "something" category unless it hasn't been reviewed.

Your direction is appreciated.


Solution

  • Updated answer to reflect logic according to your comment.

    from s in db.Items
    where <Other boolean operations> &&
          (!s.Category.Contains("something") || s.IsReviewed == false)