📒
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

Was this helpful?

  1. Silverlight Clients
  2. Customizing Generated Code

How to: Add Computed Properties on the Client

PreviousCustomizing Generated CodeNextAccessing non-Silverlight Clients

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 ]

You can add properties in the Open Ria Services client project that are computed from properties in the entity class. Partial methods are used to raise the event that notifies UI elements that the value has changed. When you add computed properties, the property only exists in the client project. This topic describes how to add such computed properties.

For more information about customizing generated code, see . For information about generating client code, see .

To add a computed property

  1. In the client project, add a class file.

  2. Declare a partial class with the same name and namespace as the entity proxy class you want to modify.

  3. Add a property that creates a new value based on one or more values in the entity proxy class.

  4. Implement the On[CustomProperty]Changed partial method for each property used in computing the new value and call the RaisePropertyChanged method to notify the framework that the computed property has changed.

    The following example shows how to calculate the total available time away from work for an employee based on vacation hours and sick leave. A change to either vacation hours or sick leave hours will produce a change in total off hours.

    Imports OpenRiaServices.Client
    
    Namespace Web
      Partial Public Class Employee
        Inherits Entity
    
        ReadOnly Property TotalOffHours() As Integer
          Get
            Return Me.SickLeaveHours + Me.VacationHours
          End Get
        End Property
    
        Private Sub OnSickLeaveHoursChanged()
          Me.RaisePropertyChanged("TotalOffHours")
        End Sub
    
        Private Sub OnVacationHoursChanged()
          Me.RaisePropertyChanged("TotalOffHours")
        End Sub
      End Class
    End Namespace
    using OpenRiaServices.Client;
    
    namespace RIAServicesExample.Web
    {
      public partial class Employee : Entity
      { 
        public int TotalOffHours 
        { 
          get { return this.SickLeaveHours + this.VacationHours; } 
        } 
        partial void OnSickLeaveHoursChanged() 
        { 
          this.RaisePropertyChanged("TotalOffHours"); 
        } 
        partial void OnVacationHoursChanged() 
        { 
          this.RaisePropertyChanged("TotalOffHours"); 
        } 
      }
    }

    You can data bind to this computed property with the following code.

    <dataForm:DataField Label="Total Off Hours"> 
      <TextBox Text="{Binding TotalOffHours, Mode=OneWay}" />
    </dataForm:DataField>
Release Notes
Changelog
Customizing Generated Code
Client Code Generation