Error creating DataServiceQuery
-
16 Eylül 2010 Perşembe 18:39
Hi,
I'm trying to write a helper method which will make queries against Azure Table Storage, handle any continuation tokens and yield the results (code below). It works fine if i want to retrieve ALL entities in a table. However if i want to pass a filter to the query (e.g. PartitionKey == "xyz") the call to CreateQuery returns the following error:
{Error translating Linq expression to URI: The expression Invoke(value(System.Func`2[SC.Services.Azure.UserActivitiesTable,System.Boolean]), [10007]) is not supported.}
where UserActivitiesTable is the TableServiceEntity i am querying against.
Any ideas? Thanks
public static IEnumerable<TSource> ExecuteContinuationQuery<TSource>(Func<TSource, bool> predicate, Action OnBatchRetrievedAction) where TSource : TableServiceEntity { AzureDataServiceContext svc = ServiceHelpers.CreateAzureTableService(); string npk = null, nrk = null; do { DataServiceQuery<TSource> query = null; if (predicate != null) { query = svc.CreateQuery<TSource>(typeof(TSource).Name).Where(a => predicate(a)).Take(1000) as DataServiceQuery<TSource>; } else { query = svc.CreateQuery<TSource>(typeof(TSource).Name).Take(1000) as DataServiceQuery<TSource>; } if (!string.IsNullOrEmpty(npk)) query = query.AddQueryOption("NextPartitionKey", npk); if (!string.IsNullOrEmpty(nrk)) query = query.AddQueryOption("NextRowKey", nrk); var response = query.Execute() as QueryOperationResponse<TSource>; npk = response.Headers.ContainsKey("x-ms-continuation-NextPartitionKey") ? response.Headers["x-ms-continuation-NextPartitionKey"] : string.Empty; nrk = response.Headers.ContainsKey("x-ms-continuation-NextRowKey") ? response.Headers["x-ms-continuation-NextRowKey"] : string.Empty; if (OnBatchRetrievedAction != null) OnBatchRetrievedAction(); foreach (var r in response) { yield return r; } } while (!string.IsNullOrEmpty(npk) || !string.IsNullOrEmpty(nrk)); }
- Taşıyan DanielOdievichEditor 28 Eylül 2010 Salı 22:43 forum migration (From:Windows Azure)
Tüm Yanıtlar
-
16 Eylül 2010 Perşembe 21:33Yanıtlayıcı
In this Azure forum thread, Jai Haridas writes that:
Predicates are not supported. However, I suspect this exception is thrown by ADO.NET Data Service aka Astoria client when it tries to convert the LINQ expression to REST Uri and sees the predicate being used.
You should read the remainder of his comment for ideas.
- Yanıt Olarak İşaretleyen Yi-Lun LuoModerator 23 Eylül 2010 Perşembe 08:43