-1

I want same field combine with ORs and between two diffferent fileds with AND.

ex - If they have the same Field value, those all ORed. This allows us to say "State", "eq", "CA", OR "State", "eq", "TX" AND "FirstName", "eq", "John".

(State==CA || State==TX) AND FirstName==John)
Rahul Singh
  • 20,580
  • 5
  • 32
  • 49
MDev
  • 41
  • 4

1 Answers1

0

There are a couple of ways you can do this:

1. Chain Where()s

You can chain together two Where() statements, the first one with the OR and the second satisfying the AND. This can get to be really useful when you have a query that you're programmatically/dynamically building:

var output = input
                .Where(a => a.State == "CA" || a.State == "TX")
                .Where(a => a.FirstName == "John");

Since the Where() filters are run in series, the effect is a logical AND of the conditions in each.

2. Parenthetical Logic

You can also just use parentheses to dictate the order of operation:

var output = input
                .Where(a => (a.State == "CA" || a.State == "TX") 
                             && a.FirstName == "John");
Community
  • 1
  • 1
eouw0o83hf
  • 8,640
  • 3
  • 51
  • 66