📒
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
  • To share a source file by using a shared naming convention
  • To share a source file by using file links

Was this helpful?

  1. Middle Tier
  2. Shared Code

How to: Share Code through Source Files

PreviousShared CodeNextSilverlight 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 ]

This topic describes how to share code, and so functionality, between the middle tier and the presentation tier of a Open Ria Services application using source files. When you change the source file in the middle tier and rebuild your application, the updated code is automatically synchronized in the client project. You put code in a shared source file when the code does not belong in a domain service or an entity class, and you do not want the code to go through the client code generation process.

You can share source files by either using a shared naming convention or by file links. This topic describes how to share source files by using both of these approaches. For information about the advantages and disadvantages of both approaches, see the topic.

This topic assumes that you have already created a Open Ria Services solution. For a description of the procedures for doing this, see the topic.

To share a source file by using a shared naming convention

  1. In Solution Explorer for a middle-tier project, create any directory structure that you want to contain shared code files.

    The directory structure will be re-created in the client project under the Generated_Code folder.

  2. Add a C# or Visual Basic code file to the directory structure.

    The file can exist anywhere in the directory structure of the middle-tier project.

  3. Depending on the language of the project, name the class by using the shared naming convention: *.shared.cs or *.shared.vb.

    For example, ExampleCode.shared.cs or ExampleCode.shared.vb.

  4. Add code to the shared code file.

  5. Build (Ctrl+Shjift+B) the solution.

  6. In the client project, open the Generated_Code folder and notice that the code file has been copied.

    At the top of Solution Explorer, you might have to click the Show All Files option in the client project to see the Generated_Code folder.

  7. Open the code file and notice that no changes have been made to the code during compilation.

To share a source file by using file links

  1. In the middle-tier project, add a new code file.

  2. Add code to the code file.

  3. In the presentation-tier project, right-click the project, select Add and then select Existing Item.

  4. Select the code file that you added to the middle tier project.

  5. On the Add button, click the down array and select Add As Link.

    When you compile the project, you will see that the file has not been copied to the client project. Instead, a reference was added to the file.

Release Notes
Changelog
Shared Code
Walkthrough: Creating a Open Ria Services Solution
RIA_SharedCodeFile