Walkthrough: Retrieving and Displaying Data From a Domain Service
This topic explains how to call the method on the domain context from a Silverlight application that corresponds to the domain service query method you want to access and then how to apply additional filtering on the results of that query to limit which entities are returned or displayed.
To retrieve data in your Silverlight application, you call the method on the domain context that corresponds to the domain service query method that you want to use. For example, a query method in the domain service named
GetProducts will have a corresponding method in the domain context named
GetProductsQuery. In your Silverlight application, you call
GetProductsQuery and that method returns an EntityQuery object.
In your Silverlight application, you can apply additional filtering on the query to limit which entities are returned. A query method may return every record from the products table, but you may only want to display the products that have a price value of less than 100. You can use LINQ and a subset of LINQ query operators to modify the results returned from the query. The following lists the available query operators:
After you apply additional filtering, you pass the EntityQuery object to a parameter in the Load method to execute the query and get the results.
If the query has a QueryAttribute with the IsComposable property set to false, you cannot apply additional filtering on the query. Generally, only queries that return a single entity will have IsComposable set to false.
You can bind the data to any Silverlight control that presents data. The DataGrid control can present the data in a table format.
This walkthrough describes how to retrieve and display data from a domain service. It also shows how to use the available query operator to apply additional filtering on a query.
This and the other walkthroughs presented in the WCF RIA Services documentation require several prerequisite programs, such as Visual Studio 2010 and the Silverlight Developer Runtime and SDK, be installed and configured properly, in addition to WCF RIA Services and the WCF RIA Services Toolkit. They also require installing and configuring SQL Server 2008 R2 Express with Advanced Services and installing the AdventureWorks OLTP and LT database.
Detailed instructions for the satisfaction of each of these prerequisites are provided by the topics within the Prerequisites for WCF RIA Services node. Follow the instructions provided there before proceeding with this walkthrough to ensure that you encounter as few problems as possible when working through this RIA Services walkthroughs.
This walkthrough assumes that you have completed the Walkthrough: Creating a RIA Services Solution and continues from the application created with the procedures described there.
Open the RIAServicesExample solution obtained from completing instructions outlined in the Walkthrough: Creating a RIA Services Solution topic.
In your Silverlight application, open the code-behind page for MainPage.xaml.
Create an EntityQuery instance by calling the
Use the available query operations to filter the customers.
Pass the query object to the Load method and assign the return value to the LoadOperation.
The following code shows how to retrieve customers from the domain service. It filters customers who have phone numbers that start with 583 and orders them alphabetically by LastName. The results are displayed in a DataGrid.