sql - Is looping through IQueryable the same as looping through a Datareader with Reader.Read() in C# -


sorry long title :)

i couldn't find answers , question has been circling through head time now. short summary of question @ end.

basically i'm wondering if linq entities/sql loops through datareader before maps resultset 1 of entities/sql classes or mapped. iqueryable have loop through data reader before can loop through iqueryable. show mean in code i'm wondering if

foreach(object o in someiqueryableobject) {     ...do stuff object } 

will result in either a:

 while(reader.read()) {      someiqueryableobject.add(reader.translaterow()); } //now iqueryable has been loaded objects , can loop through //with above code foreach(object o in someiqueryableobject) {     ...do stuff object } 

or result in b:

while(reader.read()) {     ...do stuff object } //iqueryable doesn't have loop through reader //before can loop through iqueryable. 

short summary: when use foreach on iqueryable, equivalent of looping through datareader reader.read()

afaik ef use second option. reason me saying have experienced ef open second connection when execute query while looping through results of first query. since using transaction, , disabled distributed transaction, , second open connection (while first connection still open , used) disables re-use of current transaction, second query threw exception saying dtc wasn't enabled.

so conclusion was: if executing query , looping through results (so no .tolist()), query still executing, , connection still open, , if ef using data-reader, yes, within loop reads data-reader.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -