Entity Framework List Contains in lambda(实体框架列表包含在 lambda)
问题描述
我想使用特定 ID 查询项目.例如:
I want to query items with specific IDs using. For example:
var ids = new List<int> { 1, 3, 5 };
var items = context.Items.Where(item => ids.Contains(item.ID)).ToList();
问题:
- 这是否会使用 SQL
IN
运算符生成单个查询? - 这段代码在性能方面可以吗?
- 有没有更好的方法?
- Will this generate a single query with SQL
IN
operator? - Is this code OK in terms of performance?
- Are there any better ways to do it?
我正在使用带有 Microsoft SQL Server 的 Entity Framework 6.
I am using Entity Framework 6 with Microsoft SQL Server.
推荐答案
- 这会使用 SQL IN 运算符生成单个查询吗?
是的 - 这段代码在性能方面可以吗?
是(适用于小型列表) - 有没有更好的方法?
否(对于小型列表)
如果列表真的很大并且表相当小,您可能会获得更好的性能,将完整的表放入内存并与列表进行内存连接.
If the list is really big and the table is reasonably small you might get better performance bringing the complete table into memory and do an in memory join with the list.
这篇关于实体框架列表包含在 lambda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:实体框架列表包含在 lambda


基础教程推荐
- 全局 ASAX - 获取服务器名称 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01