다음을 통해 공유


Batching Queries using the ADO.NET Data Services CLient library

Did you know you could execute batch queries using the Data Services client library ?

The API is ExecuteBatch for Synchronous access and Begin/End ExecuteBatch for asynchronous scenarios.

1) Batching a set of URI Queries .

The ExecuteBatch API accepts an array of DataServiceRequest objects.
Consider this example , you want to batch queries to be sent to the “Products” and “Categories” entity sets of a northwind service.

2) Batching Linq Queries

If you want to use strongly types Linq queries instead of string based URI queries , you can use the linq support to generate the linq query

3) How do I Identify the response if I make duplicate requests with the same ElementType ?

Consider this situation , You make 2 requests both of type DataServiceRequest<Products>  , how do you identify
which response is for which request ?

One of the scenarios  I can think of , is that the entity set contains multiple types related via inheritance .

ex: Customers entity set contains instances of types HappyCustomers and HappierCustomers inheriting from Customers.

The QueryOperationResponse type contains a Query property which returns the DataServiceRequest that this response corresponds to .

You can pass along the requests you made in the batch as a state to the callback and then compare the Query property of the QueryOperationResponse
to match the response to the request.

ex:

Comments

  • Anonymous
    March 15, 2009
    Thank you for submitting this cool story - Trackback from DotNetShoutout

  • Anonymous
    March 17, 2009
    DotNetBurner.com - news and articles about .net DotNetBurner