LINQ 是否使用 DataRelations 来优化连接? [英] Does LINQ use DataRelations to optimize joins?

查看:14
本文介绍了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 来优化连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆