开发者

How to use the IN operator in linq

I'm querying a view and filtering the resu开发者_开发知识库lts with a column named status. I'd like to query it so I can search for rows with different status, by using the IN operator as I'd do in SQL.

As so:

SELECT * FROM VIEW WHERE Status in ('....', '.....')

How can I achieve this?


If your query expression uses the Contains method of an IEnumerable object, the parser will turn that into an IN expression using the values in the IEnumerable.

List<string> foo = new List<string>() { "a", "b", "c" };

var query = dataContext.View.Where(v => foo.Contains(v.Status));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜