-2

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.

Erik Philips
  • 53,428
  • 11
  • 128
  • 150
CAD.Dev
  • 187
  • 1
  • 1
  • 12
  • To clarify, you want all filtered items to be `IsReviewed` if they are not in `Category.Contains("something")` and `!IsReviewed` if they are in `Category.Contains("something")`? Or do you not care the state of `IsReviewed` if the item is not in category? – strongbutgood Dec 30 '16 at 21:25
  • I want all filtered items to be "IsReviewed" bool agnostic (true or false), unless it is of the category "something", for them I only want those that are false. – CAD.Dev Dec 30 '16 at 21:42

3 Answers3

1

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)
strongbutgood
  • 655
  • 7
  • 22
0

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)
-1

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

Servy
  • 202,030
  • 26
  • 332
  • 449