locked
Error creating DataServiceQuery RRS feed

  • Question

  • 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));
        }
    
    

     

    • Moved by DanielOdievichEditor Tuesday, September 28, 2010 10:43 PM forum migration (From:Windows Azure)
    Thursday, September 16, 2010 6:39 PM

Answers

  • 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.

     

    • Marked as answer by Yi-Lun Luo Thursday, September 23, 2010 8:43 AM
    Thursday, September 16, 2010 9:33 PM
    Answerer