【发布时间】:2014-04-27 02:35:43
【问题描述】:
抱歉,标题太长了:)
我真的找不到任何答案,这个问题已经在我脑海中盘旋了一段时间。最后是问题的简短摘要。
基本上,我想知道 linq 到实体/sql 是否在将结果集映射到实体/sql 类之一之前循环通过数据读取器,或者它是否已经映射。在我可以循环通过 Iqueryable 之前,Iqueryable 是否必须循环通过数据读取器。为了显示我在代码中的意思,我想知道是否
foreach(object o in SomeIQueryableObject)
{
...do stuff with the object
}
将导致 A:
while(Reader.Read())
{
SomeIqueryableObject.Add(Reader.TranslateRow());
}
//now the iqueryable has been loaded with objects and we can loop through it
//with the above code
foreach(object o in SomeIQueryableObject)
{
...do stuff with the object
}
还是会导致B:
while(Reader.Read())
{
...do stuff with the object
}
//Iqueryable doesn't have to loop through Reader
//before you can loop through Iqueryable.
简短的总结:当我在 iqueryable 上使用 foreach 时,这是否相当于使用 Reader.Read() 遍历数据读取器
【问题讨论】:
标签: c# sql linq entity-framework linq-to-sql