項目が追加または削除されたとき、あるいはリストが更新されたときに通知を提供する動的なエンティティ コレクションを表します。
継承階層
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> 型は、以下のメンバーを公開しています。
コンストラクター
先頭に戻る
プロパティ
| 名前 | 説明 | |
|---|---|---|
![]() |
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 ウィンドウのルート レイアウト コントロールである StackPanel の DataContext プロパティにバインドされます。
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 名前空間
.gif)
.gif)
.gif)
.gif)
.gif)
.gif)
.gif)
.gif)
.gif)
.gif)