-1

What is the correct way to include multiple wheres in a LINQ call for OR

List<Pos> posList = DbContext.PosList
                             .Where<Pos>(p => p.Pos == "51000785" || 
                                         p => p.Pos == "123")
                             .ToList<Pos>();
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
John
  • 3,965
  • 21
  • 77
  • 163
  • 3
    You can just remove the second `p =>` - it's already been defined – Rufus L Aug 17 '17 at 01:08
  • Doing a simple google search `using two conditions in LINQ where clause` brings up [this](https://stackoverflow.com/q/7289565/465053), [this](https://stackoverflow.com/q/10333732/465053), [this](https://stackoverflow.com/q/11314203/465053) and [this](https://stackoverflow.com/q/8755176/465053) SO link. All will be helpful to get you an answer. – RBT Aug 17 '17 at 01:21

1 Answers1

10

The Linq where clause takes one expression and returns one bool value. Yours is taking two expressions each with their own return value. You would need to combine these two into one lambda expression that returns one value rather than the two separate ones in your example.

List<Pos> posList = DbContext.PosList
         .Where<Pos>(p => p.Pos == "51000785" || p.Pos == "123")
         .ToList<Pos>();
Erin
  • 316
  • 2
  • 6