DomainDataSource
Last updated
Was this helpful?
Last updated
Was this helpful?
[ This document was written for WCF Services Version 1 Service Pack 2 and might not be up to date Please see or for a list of changes since WCF RIA Services ]
Open Ria Services provides the control to simplify the interaction between the user interface and data from a domain context. With the , you can retrieve, shape, and edit data using only declarative syntax. You specify the domain context to use with the , and then call the operations that are available through that domain context.
To use the DomainDataSource control, you must add a reference in the Silverlight project to the System.Windows.Controls.DomainServices assembly. This reference is automatically added when you drag the from the Toolbox. Optionally, to use the DataGrid with , you must also add a reference to System.Windows.Controls.Data. This reference is also added automatically when you drag the DataGrid control from the Toolbox.
The host control, such as the UserControl, must contain the following namespace reference:
Optionally, to use the DataGrid control with DomainDataSource, you must also add the following namespace:
To define the domain context in declarative code, you must include the namespace of the server project. In the following example, ExampleApplication.Web is the name of the server project. You will use the name of your server project.
You specify a domain context for the and provide the name of the method to use for loading data. Then you bind presentation controls like the DataGrid to the . The following example shows a that retrieves data from a domain context named ProductDomainContext and displays the data in a DataGrid control. A query method called GetProducts() must exist on the domain service for the example to work.
The following example shows how to add a value to use for grouping.
The following example shows two filter descriptors that are connected by a logical AND statement. One filter depends on user input and one filter is specified in the declarative syntax.
The following example shows paging with the DomainDataSource.
In some cases a query method requires parameter values. Typically, a query method requires a parameter value to filter the data that is returned. The class provides the collection to facilitate adding parameters. The following example shows how to add parameter value with a value that is specified in the declarative text.
You can also add a parameter that uses a value from the user for the query. You bind a object to the user-input control that contains the value to use in the query. The following example shows how to specify a value from a ComboBox is used as the parameter value.
The DomainDataSource provides the collection to facilitate sorting on the data. In the collection, you add instances that describe the values to use for sorting the collection. You can add as many instances as you want to provide layers of sorting. You can specify if the data is sorted in ascending or descending order. The following example shows how to add a sort descriptor to the DomainDataSource. The data retrieved from the query is sorted by values in the StandardPrice property.
When you implement paging and sorting together, include at least one with its attribute assigned to a property that contains unique values, such as a primary key. Or add an OrderBy clause based on a property that contains unique values to the query in the . If you only sort the data on a property that does not contain unique values, the return values could contain inconsistent or missing data across pages.
The DomainDataSource provides the collection to facilitate grouping the data by property values. In the collection, you add instances that define the value to use for grouping. You can add as many instances as needed.
The DomainDataSource control provides the collection to enable you to filter the data that is returned by the query. By adding filters, you can specify that only entities which meet the condition in the filter are loaded from the domain context. You define the logical relationship between different filters by setting the property on the object. The property supports any value in the enumerator.
Within a instance, you set the property to specify the type of comparison to use when filtering. Filter descriptors support the operations in the enumerator.
When displaying a large number of entities, you may wish to provide paging in your user interface. The DomainDataSource control enables you to specify the number of entities to load and the number of entities to display on a page. New records are loaded only when the user navigates to a page that contains entities which have not been loaded. You set the and properties to specify the parameters for paging. Then, you bind a DataPager instance to the DomainDataSource to implement the interface for paging.
To persist data modifications, call the method on the object. To cancel changes, call the method.