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

查看:166
本文介绍了LINQ使用DataRelations来优化连接吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到任何地方的答案,在我用Reflector开始制作代码之前,我以为应该问:



假设我在DataSet中对DataTables进行以下LINQ查询:

  var list = 
from parent in parentTable.AsEnumerable( )
在cr.Field< int>(ParentID)上的childTable.AsEnumerable()中加入cr等于pr.Field< int>(ID)
其中pr.Field< string>(值)==foo
选择cr;

如果父表和子表之间存在DataRelation,使用显示的关键字段,LINQ用它?也就是说,它会找到父表中的值为foo的行,然后调用 GetChildRows 来投影子行?



还是这个我必须明确指定的东西? (如果是这样,我该怎么做?)

解决方案

我不这么认为。在这种情况下,LINQ to Objects可能只将对方视为常规枚举对象,并手动进行连接(不需要查看 DataRelation )。


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:

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;

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?)

解决方案

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天全站免登陆