次の方法で共有


DataServiceCollection<T> クラス

項目が追加または削除されたとき、あるいはリストが更新されたときに通知を提供する動的なエンティティ コレクションを表します。

継承階層

System.Object
  System.Collections.ObjectModel.Collection<T>
    System.Collections.ObjectModel.ObservableCollection<T>
      System.Data.Services.Client.DataServiceCollection<T>

名前空間:  System.Data.Services.Client
アセンブリ:  Microsoft.Data.Services.Client (Microsoft.Data.Services.Client.dll)

構文

'宣言
Public Class DataServiceCollection(Of T) _
    Inherits ObservableCollection(Of T)
'使用
Dim instance As DataServiceCollection(Of T)
public class DataServiceCollection<T> : ObservableCollection<T>
generic<typename T>
public ref class DataServiceCollection : public ObservableCollection<T>
type DataServiceCollection<'T> =  
    class
        inherit ObservableCollection<'T>
    end
JScript では、ジェネリックな型およびメソッドは使用できません。

型パラメーター

  • T
    エンティティ型。

DataServiceCollection<T> 型は、以下のメンバーを公開しています。

コンストラクター

  名前 説明
パブリック メソッド DataServiceCollection<T>() DataServiceCollection<T> クラスの新しいインスタンスを作成します。
パブリック メソッド DataServiceCollection<T>(IEnumerable<T>) クエリの実行に基づいて DataServiceCollection<T> クラスの新しいインスタンスを作成します。
パブリック メソッド DataServiceCollection<T>(DataServiceContext) 指定した DataServiceContext を使用して、DataServiceCollection<T> クラスの新しいインスタンスを作成します。
パブリック メソッド DataServiceCollection<T>(IEnumerable<T>, TrackingMode) クエリの実行に基づき、指定された追跡モードを使用して、DataServiceCollection<T> クラスの新しいインスタンスを作成します。
パブリック メソッド DataServiceCollection<T>(DataServiceContext, String, Func<EntityChangedParams, Boolean>, Func<EntityCollectionChangedParams, Boolean>) 指定された変更メソッドのデリゲートを使用して、指定された DataServiceContext を使用する DataServiceCollection<T> クラスの新しいインスタンスを作成します。
パブリック メソッド DataServiceCollection<T>(IEnumerable<T>, TrackingMode, String, Func<EntityChangedParams, Boolean>, Func<EntityCollectionChangedParams, Boolean>) クエリの実行に基づき、指定された変更メソッドのデリゲートを使用して、DataServiceCollection<T> クラスの新しいインスタンスを作成します。
パブリック メソッド DataServiceCollection<T>(DataServiceContext, IEnumerable<T>, TrackingMode, String, Func<EntityChangedParams, Boolean>, Func<EntityCollectionChangedParams, Boolean>) クエリの実行に基づき、指定された変更メソッドのデリゲートを使用して、指定された DataServiceContext を使用する DataServiceCollection<T> クラスの新しいインスタンスを作成します。

先頭に戻る

プロパティ

  名前 説明
パブリック プロパティ Continuation ページングされた結果の次のセットを返すために使用される連結オブジェクトを取得します。
パブリック プロパティ Count (Collection<T> から継承されています。)
パブリック プロパティ Item (Collection<T> から継承されています。)
プロテクト プロパティ Items (Collection<T> から継承されています。)

先頭に戻る

メソッド

  名前 説明
パブリック メソッド Add (Collection<T> から継承されています。)
プロテクト メソッド BlockReentrancy (ObservableCollection<T> から継承されています。)
プロテクト メソッド CheckReentrancy (ObservableCollection<T> から継承されています。)
パブリック メソッド Clear() (Collection<T> から継承されています。)
パブリック メソッド Clear(Boolean) コレクションからすべての項目を削除し、必要に応じて DataServiceContext からすべての項目をデタッチします。
プロテクト メソッド ClearItems (ObservableCollection<T> から継承されています。)
パブリック メソッド Contains (Collection<T> から継承されています。)
パブリック メソッド CopyTo (Collection<T> から継承されています。)
パブリック メソッド Detach DataServiceContext によるコレクション内のすべての項目の追跡を無効にします。
パブリック メソッド Equals (Object から継承されています。)
プロテクト メソッド Finalize (Object から継承されています。)
パブリック メソッド GetEnumerator (Collection<T> から継承されています。)
パブリック メソッド GetHashCode (Object から継承されています。)
パブリック メソッド GetType (Object から継承されています。)
パブリック メソッド IndexOf (Collection<T> から継承されています。)
パブリック メソッド Insert (Collection<T> から継承されています。)
プロテクト メソッド InsertItem 指定された項目を、コレクション内の指定されたインデックスの位置に追加します。 (ObservableCollection<T>.InsertItem(Int32, T) をオーバーライドします。)
パブリック メソッド Load(IEnumerable<T>) エンティティ オブジェクトのコレクションをコレクションに読み込みます。 Silverlight の WCF Data Services 5.0 クライアントではサポートされていません。
パブリック メソッド Load(T) 1 つのエンティティ オブジェクトをコレクションに読み込みます。 Silverlight の WCF Data Services 5.0 クライアントではサポートされていません。
パブリック メソッド LoadAsync() 項目がエンティティのナビゲーション プロパティを表す場合、コレクションに項目を非同期で読み込みます。 Silverlight の WCF Data Services 5.0 クライアントでのみサポートされています。
パブリック メソッド LoadAsync(IQueryable<T>) DataServiceQuery<TElement> を実行して、コレクションを非同期に読み込みます。 Silverlight の WCF Data Services 5.0 クライアントでのみサポートされています。
パブリック メソッド LoadNextPartialSetAsync データの次のページをコレクションに読み込みます。 Silverlight の WCF Data Services 5.0 クライアントでのみサポートされています。
プロテクト メソッド MemberwiseClone (Object から継承されています。)
パブリック メソッド Move (ObservableCollection<T> から継承されています。)
プロテクト メソッド MoveItem (ObservableCollection<T> から継承されています。)
プロテクト メソッド OnCollectionChanged (ObservableCollection<T> から継承されています。)
プロテクト メソッド OnPropertyChanged (ObservableCollection<T> から継承されています。)
パブリック メソッド Remove (Collection<T> から継承されています。)
パブリック メソッド RemoveAt (Collection<T> から継承されています。)
プロテクト メソッド RemoveItem (ObservableCollection<T> から継承されています。)
プロテクト メソッド SetItem (ObservableCollection<T> から継承されています。)
パブリック メソッド ToString (Object から継承されています。)

先頭に戻る

イベント

  名前 説明
パブリック イベント CollectionChanged (ObservableCollection<T> から継承されています。)
パブリック イベント LoadCompleted 非同期の読み込み操作の完了時に発生します。 Silverlight の WCF Data Services 5.0 クライアントでのみサポートされています。
プロテクト イベント PropertyChanged (ObservableCollection<T> から継承されています。)

先頭に戻る

明示的なインターフェイスの実装

  名前 説明
明示的なインターフェイスの実装プライベート メソッド IList.Add (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート メソッド IList.Contains (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート メソッド ICollection.CopyTo (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート メソッド IEnumerable.GetEnumerator (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート メソッド IList.IndexOf (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート メソッド IList.Insert (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート プロパティ IList.IsFixedSize (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート プロパティ ICollection<T>.IsReadOnly (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート プロパティ IList.IsReadOnly (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート プロパティ ICollection.IsSynchronized (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート プロパティ IList.Item (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート イベント INotifyPropertyChanged.PropertyChanged (ObservableCollection<T> から継承されています。)
明示的なインターフェイスの実装プライベート メソッド IList.Remove (Collection<T> から継承されています。)
明示的なインターフェイスの実装プライベート プロパティ ICollection.SyncRoot (Collection<T> から継承されています。)

先頭に戻る

説明

WCF Data Services には、クライアント アプリケーションでデータをコントロールにバインドすることをサポートするために DataServiceCollection<T> クラスが用意されています。 このクラスは、INotifyCollectionChanged インターフェイスを実装し、Windows Presentation Foundation (WPF) および Silverlight ベースのアプリケーションのプライマリ データ バインディング機構である ObservableCollection<T> クラスから継承します。

IEnumerable<T> インターフェイスを実装する任意のコレクションを使用して、ObservableCollection<T> バインディング コレクションを読み込むことができます。 バインディング コレクションに読み込まれた項目は、INotifyPropertyChanged インターフェイスを実装する必要があります。 詳細については、「コントロールへのデータのバインド (WCF Data Services)」を参照してください。

使用例

次の例は、WPF で SalesOrders ウィンドウを定義する XAML (Extensible Application Markup Language) の分離コード ページからの抜粋です。 ウィンドウが読み込まれると、国別にフィルターされた顧客を関連オブジェクトと共に返すクエリの結果に基づいて DataServiceCollection<T> が作成されます。 この結果は、WPF ウィンドウのルート レイアウト コントロールである StackPanelDataContext プロパティにバインドされます。

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Documents
Imports System.Windows.Input
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports System.Windows.Navigation
Imports System.Windows.Shapes
Imports System.Data.Services.Client
Imports NorthwindClient.Northwind

Partial Public Class CustomerOrdersWpf
    Inherits Window

    Private context As NorthwindEntities
    Private trackedCustomers As DataServiceCollection(Of Customer)
    Private Const customerCountry As String = "Germany"
    Private Const svcUri As String = "https://localhost:12345/Northwind.svc/"
    Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
        Try
            ' Initialize the context for the data service.
            context = New NorthwindEntities(New Uri(svcUri))

            ' Create a LINQ query that returns customers with related orders.
            Dim customerQuery = From cust In context.Customers.Expand("Orders") _
                                    Where cust.Country = customerCountry _
                                    Select cust

                ' Create a new collection for binding based on the LINQ query.
            trackedCustomers = New DataServiceCollection(Of Customer)(customerQuery)

                ' Bind the root StackPanel element to the collection
                ' related object binding paths are defined in the XAML.
            Me.LayoutRoot.DataContext = trackedCustomers
        Catch ex As DataServiceQueryException
            MessageBox.Show("The query could not be completed:\n" + ex.ToString())
        Catch ex As InvalidOperationException
            MessageBox.Show("The following error occurred:\n" + ex.ToString())
        End Try
    End Sub
    Private Sub saveChangesButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
        ' Save changes to the data service.
        context.SaveChanges()
    End Sub
End Class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using NorthwindClient.Northwind;

namespace NorthwindClient
{
    public partial class CustomerOrdersWpf : Window
    {
        private NorthwindEntities context;
        private DataServiceCollection<Customer> trackedCustomers;
        private const string customerCountry = "Germany";
        private const string svcUri = "https://localhost:12345/Northwind.svc/";

        public CustomerOrdersWpf()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Initialize the context for the data service.
                context = new NorthwindEntities(new Uri(svcUri));

                // Create a LINQ query that returns customers with related orders.
                var customerQuery = from cust in context.Customers.Expand("Orders")
                                    where cust.Country == customerCountry
                                    select cust;

                // Create a new collection for binding based on the LINQ query.
                trackedCustomers = new DataServiceCollection<Customer>(customerQuery);

                // Bind the root StackPanel element to the collection;
                // related object binding paths are defined in the XAML.
                LayoutRoot.DataContext = trackedCustomers;
            }
            catch (DataServiceQueryException ex)
            {
                MessageBox.Show("The query could not be completed:\n" + ex.ToString());
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show("The following error occurred:\n" + ex.ToString());
            }
        }
        private void saveChangesButton_Click(object sender, RoutedEventArgs e)
        {
            // Save changes to the data service.
            context.SaveChanges();
        }
    }
}

次の XAML では、前の例の WPF の SalesOrders ウィンドウを定義します。

    <Window x:Class="CustomerOrdersWpf"
             xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006" 
             Height="423" Width="679" Loaded="Window_Loaded">
    <StackPanel Orientation="Vertical" Height="Auto" Name="LayoutRoot" Width="Auto">
        <Label Content="Customer ID" Margin="20,0,0,0" />
        <ComboBox Name="customerIDComboBox" DisplayMemberPath="CustomerID" ItemsSource="{Binding}" 
                  IsSynchronizedWithCurrentItem="True" SelectedIndex="0" Height="23" Width="120" 
                  HorizontalAlignment="Left" Margin="20,0,0,0" VerticalAlignment="Center" />
        <ListView ItemsSource="{Binding Path=Orders}" Name="ordersDataGrid" Margin="34,46,34,50">
            <ListView.View>
                <GridView AllowsColumnReorder="False" ColumnHeaderToolTip="Line Items">
                    <GridViewColumn DisplayMemberBinding="{Binding Path=OrderID, Mode=OneWay}" 
                        Header="Order ID" Width="50"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=OrderDate, Mode=TwoWay}" 
                        Header="Order Date" Width="50"/>
                    <GridViewColumn DisplayMemberBinding="{Binding Path=Freight, Mode=TwoWay}" 
                        Header="Freight Cost" Width="50"/>
                </GridView>
            </ListView.View>
        </ListView>
        <Button Name="saveChangesButton" Content="Save Changes" Click="saveChangesButton_Click" 
                Width="80" Height="30" Margin="450,0,0,0"/>
    </StackPanel>
</Window>

スレッド セーフ

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

関連項目

参照

System.Data.Services.Client 名前空間

その他の技術情報

コントロールへのデータのバインド (WCF Data Services)