开发者

Linq Query If Field Is In An Array?

开发者 https://www.devze.com 2023-01-16 17:06 出处:网络
The code below is incorrect but the idea here is that I want to grab values from \"SqlTable\" where the value for \"Field\" is inside of \"Array[]\".

The code below is incorrect but the idea here is that I want to grab values from "SqlTable" where the value for "Field" is inside of "Array[]".

var Result =
    from a in SqlTable
    where a.Field is 开发者_高级运维in Array[]
    select a;


You should be able to use the Queryable.Contains Extension Method:

var result =
    from a in mySqlTable
    where myArray.Contains(a.Field)
    select a;

See also: Creating IN Queries With Linq To Sql


I'm assuming now that Field and Array[] contains values that has a equality operator in place, and that the A. Then you can write it like this:

var Result =
    from a in SqlTable
    where Array[].Any( ae => ae == a.Field)
    select a;
0

精彩评论

暂无评论...
验证码 换一张
取 消