Oper
Oper

Reputation: 339

Does first iteration over .AsEnumerable execute the entire query?

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?

Upvotes: 0

Views: 341

Answers (1)

dbraillon
dbraillon

Reputation: 1752

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.

Upvotes: 2

Related Questions