I have a linq to entity
query.
will Any()
force linq execution (like ToList()
does)?
There is very good MSDN article Classification of Standard Query Operators by Manner of Execution which describes all standard operators of LINQ. As you can see from table Any
is executed immediately (as all operators which return single value). You can always refer this table if you have doubts about manner of operator execution.
Yes, and no. The any
method will read items from the source right away, but it's not guaranteed to read all items.
The Any
method will enumerate items from the source, but only as many as needed to determine the result.
Without any parameter, the Any
method will only try to read the first item from the source.
With a parameter, the Any
method will only read items from the source until it finds one that satisfies the condition. All items are only read from the source if no items satisfies the condition until the last item.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With