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 | |
---|---|---|
DomainContext | Initializes a new instance of the DomainContext class. |
Top
Properties
Name | Description | |
---|---|---|
DomainClient | Gets the DomainClient for this context. | |
EntityContainer | Gets the EntityContainer holding all entities loaded by this context. | |
HasChanges | Gets a value indicating whether this context has any pending changes. | |
IsLoading | Gets a value indicating whether this DomainContext is currently performing a load operation. | |
IsSubmitting | Gets a value indicating whether this DomainContext is currently performing a submit operation. | |
ValidationContext | Gets or sets the Silverlight ValidationContext to use for all validation operations invoked by the DomainContext. |
Top
Methods
Name | Description | |
---|---|---|
AddReference | Adds a reference to an external DomainContext. | |
CreateEntityContainer | Creates and returns an entity container configured with EntitySet objects for all entities this DomainContext will provide access to. | |
CreateQuery<TEntity> | Creates an EntityQuery. | |
Equals | (Inherited from Object.) | |
Finalize | (Inherited from Object.) | |
GetHashCode | (Inherited from Object.) | |
GetType | (Inherited from Object.) | |
InvokeOperation(String, Type, IDictionary<String, Object>, Boolean, Action<InvokeOperation>, Object) | Executes an invoke operation. | |
InvokeOperation<TValue>(String, Type, IDictionary<String, Object>, Boolean, Action<InvokeOperation<TValue>>, Object) | Executes an invoke operation. | |
Load(EntityQuery, LoadBehavior, Action<LoadOperation>, Object) | Initiates a load operation for the specified query with the specified load behavior, callback method, and user state. | |
Load<TEntity>(EntityQuery<TEntity>) | Initiates a load operation for the specified query. | |
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. | |
Load<TEntity>(EntityQuery<TEntity>, Action<LoadOperation<TEntity>>, Object) | Initiates a load operation for the specified query with the specified callback method, and user state. | |
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. | |
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. | |
MemberwiseClone | (Inherited from Object.) | |
RaisePropertyChanged | Raises the PropertyChanged event for the specified property. | |
RejectChanges | Reverts all pending changes for this DomainContext. | |
SubmitChanges() | Submits all pending changes to the domain service. | |
SubmitChanges(Action<SubmitOperation>, Object) | Submits all pending changes to the domain service. | |
ToString | (Inherited from Object.) | |
ValidateMethod | Validates a method call. |
Top
Events
Name | Description | |
---|---|---|
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.