如何编写LINQ to SQL来选择ID在未知大小的整数数组中的行?

Met*_*uru 5 linq-to-sql

假设我想将一个整数数组传递给一个运行LINQ to SQL的方法,我怎么说"WhereID在数组[]中选择"?

jas*_*son 10

使用Contains.

int[] ids = // populate ids
var query = from e in db.SomeTable
            where ids.Contains(e.SuchID)
            select e;
Run Code Online (Sandbox Code Playgroud)

LINQ to SQL会将此转换为WHERE使用的子句IN.