Pradeep H
Pradeep H

Reputation: 613

SQL IN Query in LINQ With List

Need help in filtering LINQ select query with another List<string>

Like,

List<string> samplingList;

var Result = from F in db.TableA where F.flag == "A" && F.code in (samplingList)

F.Code.Contains() can accept only single value, How can I pass samplingList to LINQ to filter data. Basically I am looking for achieving SQL code value in ('V1', 'V2') in LINQ.

Upvotes: 1

Views: 84

Answers (1)

Salah Akbari
Salah Akbari

Reputation: 39976

What about this:

samplingList.Contains(F.code)

So your complete query should be something like this:

var Result = from F in db.TableA where F.flag == "A" &&
             samplingList.Contains(F.code)
             select F;

Upvotes: 2

Related Questions