locked
batch query not expanding navigation properties RRS feed

  • Question


  • I have built a framework to abstract the execution of batch queries, however it seems that the expansion of naviagation properties is not working as I would expect.

    What I do is (with much code removed):

     void BatchLoad(params IQueryable[] loadQuerys)
        {
          List<DataServiceRequest> dataServiceRequests = new List<DataServiceRequest>();
    
          foreach (IQueryable query in loadQuerys)
          {
            dataServiceRequests.Add((DataServiceQuery)query);
            _results.Add(new object()); // where _results was set to new List<object>()
          }
    
          _context.BeginExecuteBatch(Callback, dataServiceRequests, dataServiceRequests.ToArray());
        }
    

    And on the Callback:

     void Callback(IAsyncResult result)
        {
          DataServiceResponse batchResponse = _context.EndExecuteBatch(result);
            foreach (QueryOperationResponse response in batchResponse)
              CreateCollection(response);
         }
          
    

    The CreateCollection looks like:

     

        void CreateCollection(QueryOperationResponse response)
        {
          if (response.Query.ElementType == typeof(A) && typeof(A) != typeof(Missing))
          {
            _entityListA.Load(response.OfType<A>()); // _entityListA = new DataServiceCollection<A>(_context); 
            _results[0] = _entityListA; 
            return;
          }
          if (response.Query.ElementType == typeof(B) && typeof(B) != typeof(Missing))
          {
    ....

     

     

    Everything seems to work as expected however, when I cast the response to an IEnumerable ofType A it seem to loose its naviagation property values. In other words, say A is a Customer, Customer.Orders.Count == 0 even though the response as seen through fiddler has orders.

    Is there some reason why I can not do this? Or is there a problem else where?

     

    Wednesday, May 11, 2011 11:10 PM

Answers

  • I don't think this has anything todo with Batching...How did you call your BatchLoad method? What was the merge option on the context?
    Peter Q. http://blogs.msdn.com/peter_qian
    • Marked as answer by GAX user Thursday, May 12, 2011 2:26 PM
    Thursday, May 12, 2011 12:05 AM
    Answerer
  • As noted by Peter, please show us your query construction. This problem is typically caused by previous queries which return the same Customer instance but without its Orders. Subsequent queries will by default not update the customer (including its navigation property like Orders) unless you modify the default MergeOptions.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by GAX user Thursday, May 12, 2011 2:26 PM
    Thursday, May 12, 2011 2:25 PM
    Moderator

All replies

  • I don't think this has anything todo with Batching...How did you call your BatchLoad method? What was the merge option on the context?
    Peter Q. http://blogs.msdn.com/peter_qian
    • Marked as answer by GAX user Thursday, May 12, 2011 2:26 PM
    Thursday, May 12, 2011 12:05 AM
    Answerer
  • As noted by Peter, please show us your query construction. This problem is typically caused by previous queries which return the same Customer instance but without its Orders. Subsequent queries will by default not update the customer (including its navigation property like Orders) unless you modify the default MergeOptions.

    Thanks,


    Vitek Karas [MSFT]
    • Marked as answer by GAX user Thursday, May 12, 2011 2:26 PM
    Thursday, May 12, 2011 2:25 PM
    Moderator
  • Thanks to both of you. That is precisely what the problem was.
    Thursday, May 12, 2011 2:28 PM