这是我的代码
if (catid != 0)
posts = posts.Where(x => x.catid IN '1,8,2,109,23');
Run Code Online (Sandbox Code Playgroud)
将在此代码显示为一个语法错误.有没有办法来解决这个问题
您还必须使用其他列表进行比较.
List<int> cadIdFoundList = new List<int>();
cadIdFoundList.Add(1);
cadIdFoundList.Add(8);
// etc. . .
posts.Where(x => cadIdFoundList.Contains(x.catId));
Run Code Online (Sandbox Code Playgroud)
int[] ids = new int[] { 1, 8, 2, 109, 23 };
var query = posts.Where(x => ids.Contains(x.catid));
Run Code Online (Sandbox Code Playgroud)
Rob Conery 之前曾讨论过这个话题.