Team blog post here :
And some sample code for more context.
With the Linq pattern, here is what the code for downloading the first 10 customers would look like :
DataServiceCollection<Customer> customerCollection = new DataServiceCollection<Customer>(Context); customerCollection.Load(Context.CreateQuery<Customer>("Customers").Take(10));
Now, with the URI pattern, this is what it looks like :
DataServiceCollection<Customer> customerCollection = new DataServiceCollection<Customer>(Context); customerCollection.Load(Context.CreateQuery<Customer>("Customers").Take(10)); var top10CustomersUri = new Uri("Customers?$top=10", UriKind.RelativeOrAbsolute); Context.BeginExecute<Customer>(top10CustomersUri, (asResult) => { var top10CustomersResponse = Context.EndExecute<Customer>(asResult) as QueryOperationResponse<Customer>; customerCollection.Load(top10CustomersResponse); }, null);
We can make code a lot easier to read with an Extension method that takes a URI on the LoadAsync method.
public static class DataServiceCollectionExtensions { public static void LoadAsync<TEntity>(this DataServiceCollection<TEntity> collection, DataServiceContext context, Uri requestUri) { context.BeginExecute<TEntity>( requestUri, (asResult) => { var results = context.EndExecute<TEntity>(asResult); collection.Load(results); }, null); } }
var top10CustomersUri = new Uri("Customers?$top=10", UriKind.RelativeOrAbsolute); customerCollection.LoadAsync(Context, top10CustomersUri);