如何使用Linq和IN子句 [英] How to use Linq and the IN clause
本文介绍了如何使用Linq和IN子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
if (catid != 0)
posts = posts.Where(x => x.catid IN '1,8,2,109,23');
此代码中的中显示为语法错误.有没有办法解决这个问题
The in in this code shows as a syntax error. Is there a way to fix this
推荐答案
您还必须使用另一个列表进行比较.
You must use another list to compare too.
List<int> cadIdFoundList = new List<int>();
cadIdFoundList.Add(1);
cadIdFoundList.Add(8);
// etc. . .
posts.Where(x => cadIdFoundList.Contains(x.catId));
这篇关于如何使用Linq和IN子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文