Category isn't this unless property is false

67 views Asked by At

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.

3

There are 3 answers

8
Venkat Pasumarthi On BEST ANSWER

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)
3
Servy On

So you want all of the items where the category is NOT "something" OR IsReviewed is false.

2
strongbutgood On

Based on all the comments I am understanding you are looking for all items that aren't in Category.Contains("something") or the ones that are if they are !IsReviewed

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

You can move the negation around so you are excluding any items that are in Category.Contains("something") and are IsReviewed

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