LINQ Where in collection clause(LINQ Where in collection 子句)
问题描述
我一直在 google 上搜索,但没有找到任何对我有用的东西.
I've been looking on google but not finding anything that does the trick for me.
如您所知,SQL 有一个where x in (1,2,3)"子句,它允许您检查多个值.我正在使用 linq,但似乎找不到与上述语句相同的语法.
as you know SQL has a "where x in (1,2,3)" clause which allows you to check against multiple values. I'm using linq but I can't seem to find a piece of syntax that does the same as the above statement.
我有一个类别 ID(列表)的集合,我想根据这些集合进行检查
I have a collection of category id's (List) against which I would like to check
我发现了一些使用 .contains 方法的东西,但它甚至没有构建.
I found something that uses the .contains method but it doesn't even build.
推荐答案
你必须在你的 id 列表中使用 Contains 方法:
You have to use the Contains method on your id list:
var query = from t in db.Table
where idList.Contains(t.Id)
select t;
这篇关于LINQ Where in collection 子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LINQ Where in collection 子句
基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
