LINQ等同于SQL IN运算符 [英] What is the linq equivalent to the SQL IN operator

查看:92
本文介绍了LINQ等同于SQL IN运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用linq,我必须检查数组中是否存在行的值.
相当于sql查询:

With linq I have to check if a value of a row is present in an array.
The equivalent of the sql query:

WHERE ID IN (2,3,4,5)

我该怎么办?

推荐答案

.包含

var resultset = from x in collection where new[] {2,3,4,5}.Contains(x) select x

当然,对于您的简单问题,您可能会遇到类似这样的情况:

Of course, with your simple problem, you could have something like:

var resultset = from x in collection where x >= 2 && x <= 5 select x

这篇关于LINQ等同于SQL IN运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆