DomainContext Class

[WCF RIA Services Version 1 Service Pack 2 is compatible with either .NET framework 4 or .NET Framework 4.5, and with either Silverlight 4 or Silverlight 5.]

A DomainContext is a stateful client-side representation of a domain service, providing access to all the functionality of the service.

Inheritance Hierarchy

System.Object
  System.ServiceModel.DomainServices.Client.DomainContext
    System.ServiceModel.DomainServices.Client.ApplicationServices.AuthenticationDomainContextBase

Namespace:  System.ServiceModel.DomainServices.Client
Assembly:  System.ServiceModel.DomainServices.Client (in System.ServiceModel.DomainServices.Client.dll)

Syntax

'Declaration
Public MustInherit Class DomainContext _
    Implements INotifyPropertyChanged
'Usage
Dim instance As DomainContext
public abstract class DomainContext : INotifyPropertyChanged
public ref class DomainContext abstract : INotifyPropertyChanged
[<AbstractClassAttribute>]
type DomainContext =  
    class
        interface INotifyPropertyChanged
    end
public abstract class DomainContext implements INotifyPropertyChanged

The DomainContext type exposes the following members.

Constructors

  Name Description
Protected method DomainContext Initializes a new instance of the DomainContext class.

Top

Properties

  Name Description
Public property DomainClient Gets the DomainClient for this context.
Public property EntityContainer Gets the EntityContainer holding all entities loaded by this context.
Public property HasChanges Gets a value indicating whether this context has any pending changes.
Public property IsLoading Gets a value indicating whether this DomainContext is currently performing a load operation.
Public property IsSubmitting Gets a value indicating whether this DomainContext is currently performing a submit operation.
Public property ValidationContext Gets or sets the Silverlight ValidationContext to use for all validation operations invoked by the DomainContext.

Top

Methods

  Name Description
Public method AddReference Adds a reference to an external DomainContext.
Protected method CreateEntityContainer Creates and returns an entity container configured with EntitySet objects for all entities this DomainContext will provide access to.
Protected method CreateQuery<TEntity> Creates an EntityQuery.
Public method Equals (Inherited from Object.)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode (Inherited from Object.)
Public method GetType (Inherited from Object.)
Public method InvokeOperation(String, Type, IDictionary<String, Object>, Boolean, Action<InvokeOperation>, Object) Executes an invoke operation.
Public method InvokeOperation<TValue>(String, Type, IDictionary<String, Object>, Boolean, Action<InvokeOperation<TValue>>, Object) Executes an invoke operation.
Public method Load(EntityQuery, LoadBehavior, Action<LoadOperation>, Object) Initiates a load operation for the specified query with the specified load behavior, callback method, and user state.
Public method Load<TEntity>(EntityQuery<TEntity>) Initiates a load operation for the specified query.
Public method Load<TEntity>(EntityQuery<TEntity>, Boolean) Initiates a load operation for the specified query with the specified value indicating whether an error results in an exception.
Public method Load<TEntity>(EntityQuery<TEntity>, Action<LoadOperation<TEntity>>, Object) Initiates a load operation for the specified query with the specified callback method, and user state.
Public method Load<TEntity>(EntityQuery<TEntity>, LoadBehavior, Boolean) Initiates a load operation for the specified query with the specified load behavior, and value indicating whether an error results in an exception.
Public method Load<TEntity>(EntityQuery<TEntity>, LoadBehavior, Action<LoadOperation<TEntity>>, Object) Initiates a load operation for the specified query with the specified load behavior, callback method, and user state.
Protected method MemberwiseClone (Inherited from Object.)
Protected method RaisePropertyChanged Raises the PropertyChanged event for the specified property.
Public method RejectChanges Reverts all pending changes for this DomainContext.
Public method SubmitChanges() Submits all pending changes to the domain service.
Public method SubmitChanges(Action<SubmitOperation>, Object) Submits all pending changes to the domain service.
Public method ToString (Inherited from Object.)
Protected method ValidateMethod Validates a method call.

Top

Events

  Name Description
Public event PropertyChanged Raised whenever a DomainContext property changes.

Top

Remarks

For each domain service in the server project, WCF RIA Services generates a class that derives from DomainContext. You use the generated DomainContext class to interact with the domain service. You retrieve data by calling the Load method and passing one of the generated query methods as a parameter. You save changes in the data by calling the SubmitChanges method. You cancel all pending data changes and revert the data to its previous state by calling the RejectChanges method. The generated class contains query methods that correspond to query methods in the domain service. By default, RIA Services uses a naming convention for the generated domain context and its methods. For example, a domain service in the server project named CustomerDomainService will have a domain context class in the client project named CustomerDomainContext. A query method named GetCustomers has a corresponding method in the client project named GetCustomersQuery. For more information, see Client Code Generation.

To find the generated domain context class, select Show All Files in the Silverlight project and open the Generated_Code folder.

When you execute a domain operation, the operation is processed asynchronously. To take an action after the operation has completed, you must provide a callback method. An example of providing a callback method is shown below.

Examples

The following example shows how to create an instance of a generated DomainContext class and load data from a query.

Imports System.Windows.Ria
Imports RIAServicesExample.Web

Partial Public Class MainPage
    Inherits UserControl

    Private _customerContext As New CustomerDomainContext

    Public Sub New()
        InitializeComponent()

        Dim loadOp = Me._customerContext.Load(Me._customerContext.GetCustomersQuery())
        CustomerGrid.ItemsSource = loadOp.Entities
    End Sub

End Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using RIAServicesExample.Web;
using System.Windows.Ria;

namespace RIAServicesExample
{
    public partial class MainPage : UserControl
    {
        private CustomerDomainContext _customerContext = new CustomerDomainContext();

        public MainPage()
        {
            InitializeComponent();

            LoadOperation<Customer> loadOp = this._customerContext.Load(this._customerContext.GetCustomersQuery());
            CustomerGrid.ItemsSource = loadOp.Entities;
        }
    }
}

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.ServiceModel.DomainServices.Client Namespace