Export (0) Print
Expand All

DomainContext Class

WCF RIA Services

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

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

public abstract class DomainContext : INotifyPropertyChanged

The DomainContext type exposes the following members.

  NameDescription
Protected methodDomainContextInitializes a new instance of the DomainContext class.
Top

  NameDescription
Public propertyDomainClientGets the DomainClient for this context.
Public propertyEntityContainerGets the EntityContainer holding all entities loaded by this context.
Public propertyHasChangesGets a value indicating whether this context has any pending changes.
Public propertyIsLoadingGets a value indicating whether this DomainContext is currently performing a load operation.
Public propertyIsSubmittingGets a value indicating whether this DomainContext is currently performing a submit operation.
Public propertyValidationContextGets or sets the Silverlight ValidationContext to use for all validation operations invoked by the DomainContext.
Top

  NameDescription
Public methodAddReferenceAdds a reference to an external DomainContext.
Protected methodCreateEntityContainerCreates and returns an entity container configured with EntitySet objects for all entities this DomainContext will provide access to.
Protected methodCreateQuery<TEntity>Creates an EntityQuery.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodInvokeOperation(String, Type, IDictionary<String, Object>, Boolean, Action<InvokeOperation>, Object)Executes an invoke operation.
Public methodInvokeOperation<TValue>(String, Type, IDictionary<String, Object>, Boolean, Action<InvokeOperation<TValue>>, Object)Executes an invoke operation.
Public methodLoad(EntityQuery, LoadBehavior, Action<LoadOperation>, Object)Initiates a load operation for the specified query with the specified load behavior, callback method, and user state.
Public methodLoad<TEntity>(EntityQuery<TEntity>)Initiates a load operation for the specified query.
Public methodLoad<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 methodLoad<TEntity>(EntityQuery<TEntity>, Action<LoadOperation<TEntity>>, Object)Initiates a load operation for the specified query with the specified callback method, and user state.
Public methodLoad<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 methodLoad<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 methodMemberwiseClone (Inherited from Object.)
Protected methodRaisePropertyChangedRaises the PropertyChanged event for the specified property.
Public methodRejectChangesReverts all pending changes for this DomainContext.
Public methodSubmitChanges()Submits all pending changes to the domain service.
Public methodSubmitChanges(Action<SubmitOperation>, Object)Submits all pending changes to the domain service.
Public methodToString (Inherited from Object.)
Protected methodValidateMethodValidates a method call.
Top

  NameDescription
Public eventPropertyChangedRaised whenever a DomainContext property changes.
Top

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.

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

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;
        }
    }
}


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