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
INoperator? - 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
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 将数据集转换为列表 2022-01-01
- 如果条件可以为空 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
