[英]Linq - Using array in Lambda expression to fetch multiple records
Im not sure wether this is possible or not. 我不确定这是否可行。 I'd like to create an array (or list/dictionary) containing some simple id's and the use the array (or whatever) in a lambda expression.
我想创建一个包含一些简单id的数组(或列表/字典),并在lambda表达式中使用数组(或其他)。
The example below should return the UserId's 15850 and 15858 下面的示例应该返回UserId的15850和15858
DbDataContext db = new DbDataContext();
int[] userIds = {15850, 15858};
var users = db.tblUsers.Where(x => x.UserId.Equals(userIds));
Possible or not? 可能与否?
Thanks 谢谢
It's possible, and will translate into a SQL WHERE IN (...)
statement, but it is written kind of backwards in linq: 这是可能的,并将转换为SQL
WHERE IN (...)
语句,但它在linq中被反向写入:
DbDataContext db = new DbDataContext();
int[] userIds = {15850, 15858};
var users = db.tblUsers.Where(x => userIds.Contains(x.UserId));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.