DomainContext クラス

DomainContext はドメイン サービスのステートフルなクライアント側表現であり、サービスのすべての機能へのアクセスを提供します。

名前空間: System.ServiceModel.DomainServices.Client
アセンブリ: System.ServiceModel.DomainServices.Client (system.servicemodel.domainservices.client.dll 内)

使用方法

'使用
Dim instance As DomainContext

構文

'宣言
Public MustInherit Class DomainContext
    Implements INotifyPropertyChanged
public abstract class DomainContext : INotifyPropertyChanged
public ref class DomainContext abstract : INotifyPropertyChanged
public abstract class DomainContext implements INotifyPropertyChanged
public abstract class DomainContext implements INotifyPropertyChanged

生成された DomainContext クラスのインスタンスを作成し、クエリからデータを読み込む方法を次の例に示します。

Imports System.ServiceModel.DomainServices.Client
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.ServiceModel.DomainServices.Client;

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

解説

サーバー プロジェクトの各ドメイン サービスに対して、WCF RIA Services は DomainContext から派生するクラスを生成します。生成された DomainContext クラスを使用して、ドメイン サービスと対話します。Load メソッドを呼び出し、生成されたクエリ メソッドのいずれかをパラメーターとして渡すことによって、データを取得します。SubmitChanges メソッドを呼び出して、データの変更を保存します。RejectChanges メソッドを呼び出して、保留中のすべてのデータ変更を取り消し、データを以前の状態に戻します。生成されたクラスには、ドメイン サービスのクエリ メソッドに対応するクエリ メソッドがあります。既定では、RIA Services は生成されたドメイン コンテキストおよびそのメソッドの名前付け規則を使用します。たとえば、サーバー プロジェクトの CustomerDomainService という名前のドメイン サービスの場合、クライアント プロジェクトのドメイン コンテキスト クラスには CustomerDomainContext という名前が付けられます。GetCustomers という名前のクエリ メソッドの場合、クライアント プロジェクトには GetCustomersQuery という名前の対応するメソッドがあります。詳細については、「Client Code Generation」を参照してください。

生成されたドメイン コンテキスト クラスを検索するには、Silverlight プロジェクトで [すべてのファイルを表示] をクリックし、[Generated_Code] フォルダーを開きます。

ドメイン操作の実行時は、操作が非同期に処理されます。操作が完了した後にアクションを実行するには、コールバック メソッドを用意する必要があります。コールバック メソッドを用意する場合の例を次に示します。

継承階層

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

スレッド セーフ

この型の public static (Visual Basic では Shared) メンバーは、スレッド セーフです。インスタンス メンバーの場合は、スレッド セーフであるとは限りません。

プラットフォーム

開発プラットフォーム

Windows XP Home Edition, Windows XP Professional, Windows Server 2003 、Windows Server 2008、および Windows 2000

ターゲット プラットフォーム

Change History

参照

リファレンス

DomainContext のメンバー
System.ServiceModel.DomainServices.Client 名前空間