如何使用Linq和IN子句 [英] How to use Linq and the IN clause

查看:428
本文介绍了如何使用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屋!

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