Вот мой код
if (catid != 0)
posts = posts.Where(x => x.catid IN '1,8,2,109,23');
В в этом коде показывает синтаксической ошибкой. Есть ли способ зафиксировать это
Вы должны использовать другой список для сравнения.
List<int> cadIdFoundList = new List<int>();
cadIdFoundList.Add(1);
cadIdFoundList.Add(8);
// etc. . .
posts.Where(x => cadIdFoundList.Contains(x.catId));
int[] ids = new int[] { 1, 8, 2, 109, 23 };
var query = posts.Where(x => ids.Contains(x.catid));
Роб Конери обсуждал эту тему раньше.
Или еще проще:
var query = posts.Where(x => new[] { 1, 8, 2, 109, 23 }.Contains(x.catid));
Может быть, что-то более похожее на:
HashSet<int> categories = new HashSet<int>() { 1, 2, 8, 23, 109};
posts = posts.Where(post => categories.Contains(post.catid));