Does LINQ use DataRelations to optimize joins?(LINQ 是否使用 DataRelations 来优化连接?)
问题描述
我在任何地方都找不到这个问题的答案,在我开始使用 Reflector 浏览生成的代码之前,我认为值得一问:
I can't find the answer to this anywhere, and before I start pawing through generated code with Reflector I thought it'd be worth asking:
假设我对数据集中的数据表运行以下 LINQ 查询:
Suppose I have the following LINQ query run against DataTables in a DataSet:
var list =
from pr in parentTable.AsEnumerable()
join cr in childTable.AsEnumerable() on cr.Field<int>("ParentID") equals pr.Field<int>("ID")
where pr.Field<string>("Value") == "foo"
select cr;
如果父表和子表之间存在使用所示关键字段的 DataRelation,LINQ 会使用它吗?也就是说,它会在父表中找到 Value 为foo"的行,然后调用 GetChildRows 来投影子行吗?
If there's a DataRelation between the parent table and the child table that uses the key fields shown, will LINQ use it? That is, will it find the rows in the parent table for which Value is "foo" and then call GetChildRows to project the child rows?
或者这是我必须明确指定的吗?(如果是这样,我该怎么做?)
Or is this something that I have to specify explicitly? (And if so, how do I do this?)
推荐答案
我不这么认为.在这种情况下,LINQ to Objects 可能只会将两侧视为常规可枚举对象,并手动进行连接(无需查看 DataRelation).
I don't think so. In this case, LINQ to Objects will probably just treat the two sides as regular enumerable objects, and do the join manually (without looking at the DataRelation).
这篇关于LINQ 是否使用 DataRelations 来优化连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LINQ 是否使用 DataRelations 来优化连接?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
