📒
OpenRiaServices
  • Start
  • Prerequisites for Open Ria Services
    • Walkthrough: Installing and Configuring SQL Server 2008 R2 Express with Advanced Services
    • Walkthrough: Installing the AdventureWorks OLTP and LT sample databases
  • Creating Open Ria Services Solutions
    • Walkthrough: Taking a Tour of Open Ria Services
    • Walkthrough: Creating a Open Ria Services Solution
    • Walkthrough: Creating a Open Ria Service with the Code First Approach
    • Walkthrough: Using the Silverlight Business Application Template
    • Walkthrough: Creating a Open Ria Services Class Library
    • Walkthrough: Localizing a Business Application
    • How to: Create a Domain Service that uses POCO-defined Entities
    • How to: Add or Remove a Open Ria Services Link
    • Using the Domain Service Wizard
  • Building Secure Applications with Open Ria Services
  • Deploying and Localizing a Open Ria Services Solutions
    • Troubleshooting the Deployment of a Open Ria Services Solution
    • Troubleshooting the Deployment of a Open Ria Services Solution
    • Walkthrough: Localizing a Business Application
  • Middle Tier
    • Domain Services
      • Walkthrough: Adding Query Methods
      • How to: Add Business Logic to the Domain Service
      • How to: Create a Domain Service that uses POCO-defined Entities
      • How to: Use HTTPS with a Domain Service
    • Data
      • Compositional Hierarchies
      • Presentation Models
      • Inheritance in Data Models
      • Complex Types
      • Shared Entities
      • Walkthrough: Sharing Entities between Multiple Domain Services
      • How to: Add Metadata Classes
      • How to: Validate Data
      • Managing Data Concurrency
    • Shared Code
      • How to: Share Code through Source Files
      • Walkthrough: Creating a Open Ria Services Class Library
  • Silverlight Clients
    • Client Code Generation
    • DomainContext and Operations
    • DomainDataSource
    • Error Handling on the Client
    • Customizing Generated Code
      • How to: Add Computed Properties on the Client
  • Accessing non-Silverlight Clients
    • ASP.NET Clients
    • Walkthrough: Using the Domain Service in ASP.NET Applications
  • Authentication, Roles, and Profiles
    • How to: Enable Authentication in Open Ria Services
    • How to: Enable Roles in Open Ria Services
    • How to: Enable Profiles in Open Ria Services
    • How to: Create a Custom Authorization Attribute
    • Walkthrough: Using Authentication Service with Silverlight Business Application
    • Walkthrough: Using Authentication Service with Silverlight Navigation Application
  • End-to-EndScenarios
    • Walkthrough: Retrieving and Displaying Data From a Domain Service
    • Walkthrough: Editing Data From a Domain Service
    • Walkthrough: Displaying Data in a Silverlight Business Application
    • Walkthrough: Displaying Related Data in a Silverlight Business Application
Powered by GitBook
On this page
  • Prerequisites
  • To retrieve and display data from a domain service
  • See Also

Was this helpful?

  1. End-to-EndScenarios

Walkthrough: Retrieving and Displaying Data From a Domain Service

PreviousEnd-to-EndScenariosNextWalkthrough: Editing Data From a Domain Service

Last updated 4 years ago

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 ]

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 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:

  • Where

  • OrderBy

  • ThenBy

  • Skip

  • Take

After you apply additional filtering, you pass the object to a parameter in the method to execute the query and get the results.

If the query has a with the property set to false, you cannot apply additional filtering on the query. Generally, only queries that return a single entity will have 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.

Prerequisites

This and the other walkthroughs presented in the Open Ria Services documentation require several prerequisite programs, such as Visual Studio and the Silverlight Developer Runtime and SDK, be installed and configured properly, in addition to Open Ria Services and the Open 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 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 Open Ria Services walkthroughs.

To retrieve and display data from a domain service

  1. In your Silverlight application, open the code-behind page for MainPage.xaml.

  2. Use the available query operations to filter the customers.

  3. 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.

    Partial Public Class MainPage
        Inherits UserControl
    
        Private _customerContext As New CustomerDomainContext
    
        Public Sub New()
            InitializeComponent()
    
            Dim query As EntityQuery(Of Customer)
    
            query = _
                From c In Me._customerContext.GetCustomersQuery() _
                Where c.Phone.StartsWith("583") _
                Order By c.LastName
    
            Dim loadOp = Me._customerContext.Load(query)
            CustomerGrid.ItemsSource = loadOp.Entities
        End Sub
    
    End Class
    public partial class MainPage : UserControl
    {
        private CustomerDomainContext _customerContext = new CustomerDomainContext();
    
        public MainPage()
        {
            InitializeComponent();
            EntityQuery<Customer> query = 
                from c in _customerContext.GetCustomersQuery()
                where c.Phone.StartsWith("583")
                orderby c.LastName
                select c;
            LoadOperation<Customer> loadOp = this._customerContext.Load(query);
            CustomerGrid.ItemsSource = loadOp.Entities;
        }
    }

See Also

Tasks

This walkthrough assumes that you have completed the and continues from the application created with the procedures described there.

Open the RIAServicesExample solution obtained from completing instructions outlined in the topic.

Create an instance by calling the GetCustomersQuery method.

Pass the query object to the method and assign the return value to the .

Release Notes
Changelog
EntityQuery\
EntityQuery\
Load
QueryAttribute
IsComposable
IsComposable
Prerequisites for Open Ria Services
Walkthrough: Creating a Open Ria Services Solution
Walkthrough: Creating a Open Ria Services Solution
EntityQuery\
Load
LoadOperation\
Walkthrough: Creating a Open Ria Services Solution
Walkthrough: Adding Query Methods