About

I am a software developer in Seattle, building a new AI software company.

Ads

August 2009

Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          

Ads


« Office Reinvention | Main | Form versus Function in Office 12 »

September 15, 2005

Comments

"""Queries are also "live" and reusable. If the original data source or collection changes, the results of the queries also change."""

Where is this defined? Which data sources are we talking about here?

Obviously, this isnt defined for IEnumerable, so is there another datasource for which it is?

Wesner Moise

This is actually true for IEnumerable... the .NET implementation of a lazy list.

It is true for Linq implementations of objects, XML and relational data. To eliminate deferred execution and cache the results, ToList() or ToArray() must be called.

IEnumerable returns a sequence based on the current live state of the object. Queries are deferred until a call to GetEnumerator() is made--which usually means until foreach is used.

If you use the System.Query APIs, the various functions Where, Select, OrderBy, GroupBy take an enumerable and return an enumerable that contains a pointer to the original enumerable. No call to GetEnumerator() on the original enumerable is ever made until the that of the final enumerable is called.

So, all execution is actually deferred. If the original objects are changed. That change is reflected when the next query is foreach'ed over.

The comments to this entry are closed.