Hit this little hurdle recently while creating WCF Data Service against Azure Table Storage. At the moment only a handful of operators are supported by the client library when using the Table Storage Service.
Supported Query Operators
| LINQ operator | Table service support | Additional information |
| From | Supported as defined. | |
| Where | Supported as defined. | |
| Take | Supported, with some restrictions. | The value specified for the Take operator must be less than or equal to 1,000. If it is greater than 1,000, the service returns status code 400 (Bad Request). If the Take operator is not specified, a maximum of 1,000 entries will be returned. |
| First, FirstOrDefault | Supported. | |
What this means is that we can not perform LINQ queries that group, order by, distinct or even return single entity properties from the query (we must always return the entire entity). In most situations the solution is to construct our LINQ queries that first make use of the supported operators and then use AsEnumerable() followed by any operations that are not supported. This generates two parts to the LINQ query. The first part (everything before the AsEnumerable) gets sent to the backend (Azure Table Storage in this case) and the remaining parts execute locally against the results of the first (in-memory). This helps get over the road-block but as you can image you are bringing a greater chunk of data down to the client and continuing processing there.
Some examples:
Using Distinct()
var query = myTableServiceContext.MyEntity.Where(e => e.Category == someCatgeory).AsEnumerable().Select(c => c.Name).Distinct();
Select next 5 entities after a given date and time (using OrderBy together with Take)
var query = myTableServiceContext.MyEntity.Where(e => e.Category == someCatgeory & e.StartDate > DateTime.UtcNow).AsEnumerable().OrderBy(o => o.StartDate).Take(5);
For further details check out the online documentation.