When building scalable data applications, developers should consider implementing the best practice in both the design and architecture to deliver applications that are responsive, maintainable and scalable. One of the common data access practice is to implement server data operation to increase the overall performance of the client application. Server data operation processes the query in the server and returns shaped results to the client. For more information about the basics of data access and the data operation types, see Data Access Overview.
Most of the built-in Silverlight data controls support only client data operation which require complete data source to work properly. On the other hands, ClientUI data controls are designed to fully support server data operation enabling you to leverage the best implementation for scalable and high-performance data applications.
Controls that support server data operation are built with advanced architecture in which it allows the data operation to be completely delegated to the server by providing the necessary query information to the developers. In this case, these controls are no longer required to process further actions in the client-side. The processes of the entire data life cycle – from capturing the query information from the views, forwarding the query to the service, to processing the final results – require a solid data component that manages and streamlines these processes in order to deliver reliable and consistent results.
ClientUI includes a built-in data component, named QueryDescriptor, to provide an elegant solution to address the requirements discussed above.
QueryDescriptor is an intermediary object that contains the query information which you can use to process the query to a service for data retrieval. The query information is stored in three different properties as shown in the following figure.
As you can see in the above figure, there are three properties which contain specific query information.
- The FilterDescriptors contains a collection of FilterDescriptor that hold filtering information.
- The SortDescriptors contains a collection of SortDescriptor that hold sorting information.
- The PageDescriptor contains information about data paging.
QueryDescriptor provides a QueryChanged event that will be raised when any of the descriptor properties change. The QueryChanged event serves as a centralized pipeline where you want to handle all the query changes due to the actions in data controls.
Data Access the MVVM-Way using QueryDescriptor
As discussed in the above section, server data operation processes the query entirely in the server side, while the data controls simply provide the query information. All ClientUI data controls centralized the query information in a QueryDescriptor object.
Configuring QueryDescriptor for Data Access
The following examples show how to bind the QueryDescriptor to data controls using MVVM pattern.
Notice that the LoadProducts() is not implemented in the above example and will be discussed in the latter section. Next, you bind the ViewModel to the UXGridView control.
Since the QueryDescriptor is bound to the ViewModel, you will now be able to handle data operation in the QueryChanged event handler. This is exactly the point where you can capture the query information from the QueryDescriptor and pass it to a data service for further processing.
ClientUI includes data providers that make it easy for you to parse the query information stored in the QueryDescriptor. It enables you to execute a server query and takes account the dynamic query provided in the QueryDescriptor in a single line of code. In this release, ClientUI provides two data providers, the first is designed for WCF RIA Services and the other is for DevForce Services. For more information about ClientUI data services, see Data Access Overview.
Parsing QueryDescriptor and Retrieving Data from WCF RIA Services
To parse the QueryDescriptor to EntityQuery in WCF RIA, you need to add the Intersoft.Client.Data.Provider.Ria assembly to your project references. This data provider assembly provides additional extensions methods to EntityQuery that will allow you to easily parse the QueryDescriptor to the EntityQuery in WCF RIA.
The following code shows how to parse the QueryDescriptor to an EntityQuery using WCF RIA Services.
As shown in the above example, the query implementation is straightforward. You just need to call the Parse() method to produce an EntityQuery that WCF RIA can process.
Parsing QueryDescriptor and Retrieving Data from DevForce Services
Similar to WCF RIA's EntityQuery, you can also parse the QueryDescriptor to a EntityQuery in DevForce using similar approaches, with minor adjustments. To get started, you need to add the Intersoft.Client.Data.Provider.DevForce assembly to your project references. This data provider assembly provides additional extensions methods to EntityQuery that will allow you to easily parse the QueryDescriptor to the EntityQuery in DevForce.
The following code shows how to parse the QueryDescriptor to an EntityQuery using DevForce Services.
Using QueryDescriptor for Custom Data Operation
Although QueryDescriptor is primarily built to support ClientUI data controls, you can eventually take advantage of its capability to store your own query information and parse it to your preferered data service for further data processing in your application.
Consider the following scenario where you have a search form to filter products data based on the input criterias.
In this case, you can populate your own QueryDescriptor based on the input fields and parse it to a data service such as shown in the following example.
For more information about data filtering using QueryDescriptor, see How-to: Programmatically Filter Data using Query Descriptor.