http://convective.wordpress.com/2010/02/06/queries-in-azure-tables/
This is a follow-up to a post on Azure Tables providing additional information on queries against the Azure Table Service.
CreateQuery<T>()
There are several classes involved in querying Azure Tables using the Azure Storage Client library. However, there is a single method central to the querying process and that isCreateQuery<T>() in the DataServiceContext class. CreateQuery<T>() is declared:
public DataServiceQuery<T> CreateQuery<T>(String entitySetName);
This method is used implicitly or explicitly in every query against Azure Tables using the Storage Client library.The CreateQuery<T>() return type is DataServiceQuery which implements both the IQueryable<T> and IEnumerable<T> interfaces. IQueryable<T>provides functionality to query data sources while IEnumerable<T> provides functionality to enumerate the results of these queries.
The following example demonstrates a trivial use of CreateQuery<T>() and the Take() operator to retrieve ten records from the Songs table in Development Storage:
public Type ResolveEntityType(String name)
{
return typeof(Song);
}
As with other LINQ implementations thequery is not submitted to the Storage Service until the query results are enumerated by ToList<Song>().
protected void SimpleQuery(CloudTableClient cloudTableClient) { TableServiceContext tableServiceContext = cloudTableClient.GetDataServiceContext(); tableServiceContext.ResolveType = ResolveEntityType; IQueryable<Song> songs = (from entity in tableServiceContext.CreateQuery<Song>(“Songs”) select entity).Take(10); List<Song> songsList = songs.ToList<Song>(); }
CloudTableQuery
The DataServiceQuery class does not provide any methods to support continuation of queries when the Azure Table Service returns continuation tokens indicating that there are additional query results awaiting retrieval. The CloudTableQuery<T> class provides that support.
If you’re using the REST API to access the table, the HTTP response header returns a continuation token. If you resubmit the same query with this continuation token in the header of the request, it will resume the query where it left off, returning the next page.
When using the SDK API, the presence of continuation tokens is not obvious, because it’s not explicitly exposed by the API (although there is a way to access them). The good news is that the SDK API knows how to handle the continuation so you don’t need to, by letting a CloudTableQuery object execute the query for you.
AsTableServiceQuery() is an extension function that returns a new CloudTableQuery object that wraps the original query object with the code to handle continuations.