Search code examples
c#entity-frameworklinqlinq-to-entities

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.


Solution

  • 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;