To have the SDP limits applied to an entity set on the server-side , you need to configure the page size on that entity set by using the SetEntitySetPageSize API available on DataServiceConfiguration.
int requestSizeLimit = 5; config.SetEntitySetPageSize("*", requestSizeLimit);
From the metadata, no way. We don’t expose any information in the $metadata endpoint that a particular set is paged on the server-side. Without browsing to each entity set exposed by the service and asking for all the entities , there is no way to detect that a set is server paged. The client developer has to know that the paging limits are set on the server-side to change the client code accordingly. For more information about client side Querying strategies , please see the section :
Applying a QueryInterceptor to an entity set would cause the total visible amount of data to the Data Service to be filtered. If the Server can’t see it , it can’t page it. In other words, any limits that are currently in place now and apply to the /EntitySet endpoint , will continue to hold after enabling Server Driven paging for that Entity Set.
With the introduction of the SDP and DataBinding support in the client library , we have a new collection type called DataServiceCollection which provides support for natively reading the NextLinkUri , if it‘s present in the ATOM returned from the server. The type contains a property called Continuation,which contains the nextLinkUri present in the payload.
DataServiceCollection<T>.Continuation Property on MSDN The simplest example of using this collection type is to use the DataServiceCollection type to hold the results of a Query. The attached sample application contains more scenario based examples.
//Create an empty DataServiceCollection to hold the results of a query DataServiceCollection<Customer> customersPagedCollection = new DataServiceCollection<Customer>(); var customersQuery = (from c in ServiceContext.Customers where c.Name.StartsWith("P") select c) as DataServiceQuery<Customer>; //Execute the query asynchronously customersQuery.BeginExecute( (asyncResult) => { var customerQueryResponse = customersQuery.EndExecute(asyncResult) as QueryOperationResponse<Customer>; //Call load on the DataServiceCollection with the QueryOperationResponse //This will cause the collection to load the customer objects //and the nextlink as found in the response. customersPagedCollection.Load( customerQueryResponse ); }, null );
Seeing as it is that the above pattern of querying for top level collections is a common practice in Silverlight applications, we’ve introduced a method on the DataServiceCollection type to make this easier. Behold, the LoadAsync method on DataServiceCollection<T> for materializing top level collections without any user code. And the LoadNextPartialSetAsync method to load the next page in the collection.
To load the next page in the Collection, call the Execute<T>,BeginExecute<T> overloads which take a continuation token.
//To Load the next page, call the Execute<T> overload which takes a continuation token ServiceContext.BeginExecute(customersPagedCollection.Continuation, QueryCallback, null);
Call the LoadNextPartialSetAsync method in your Silverlight applications:
customersPagedCollection.LoadNextPartialSetAsync();
QueryOperationResponse<T>.GetContinuation Method on MSDN
/// <summary> /// Custom collection type to illustrate pluggability of Continuation token. /// </summary> /// <typeparam name="TEntity">The Entitytype of the collection</typeparam> public class MyCollectionType<TEntity> : List<TEntity> where TEntity : class, new() { /// <summary> /// This is a custom property on a collection type which can hold the continuation token /// Call GetContinuation on the response to get the continuation token for the response /// </summary> public DataServiceQueryContinuation<TEntity> NextLink { get; set; } }
//Create the custom collection type and add the results of the query to the collection MyCollectionType<Customer> customCustomersCollection = new MyCollectionType<Customer>(); var customersQuery = (from c in ServiceContext.Customers where c.Name.StartsWith("P") select c) as DataServiceQuery<Customer>; //Execute the query asynchronously customersQuery.BeginExecute( (asyncResult) => { var customerQueryResponse = customersQuery.EndExecute(asyncResult) as QueryOperationResponse<Customer>; foreach (Customer customerInstance in customerQueryResponse) { customCustomersCollection.Add(customerInstance); } //Calling GetContinuation without any parameters gives you the nextlink of the //top level feed element in the response customCustomersCollection.NextLink = customerQueryResponse.GetContinuation(); }, null );
//To Load the next page, call the Execute<T> overload which takes a continuation token ServiceContext.BeginExecute(customCustomersCollection.NextLink , QueryCallback, null);
Thanks for the post. I would add that when configuring the service, to change the protocol version, it's first necessary to change the config parameter type from IDataServiceConfiguration interface to DataServiceConfiguration class, as explained here: <a href="blogs.msdn.com/.../a>
The interface does not have DataServiceBehavior property.
Hi Phani,
I am building a WPF app and want to load just the current page because i have thousands of records and i show only 100 records at a time.
I clear the observable collection before loading it with fresh data.
Is there a way to navigate back to previous server side page?