If i've got a linq to sql var (eg: var x = from y in db.Orders ....) and than i call .AsEnumerable() over that, if i iterate over this elements, Does the first iteration execute the ENTIRE query? or are parts of them generated in the foreach loop?
Asked
Active
Viewed 293 times
1 Answers
2
AsEnumerable
will deffer the execution of the query, if you use it in a foreach loop, the query will be executed, the result loaded into memory then you will loop through it.
Check the answer from @Gert Arnold
in this post, it might be useful.
-
so this is executed entirely before the first iteration? foreach (x in linqtosql) <-- here is executed? – Oper Mar 01 '17 at 22:43
-
Basically yes, see this MSDN post about query execution. https://msdn.microsoft.com/en-us/library/bb738633.aspx – dbraillon Mar 01 '17 at 22:47