DataServiceCollection<T> 构造函数
定义
创建 DataServiceCollection<T> 类的新实例。Creates a new instance of the DataServiceCollection<T> class.
重载
DataServiceCollection<T>()
创建 DataServiceCollection<T> 类的新实例。Creates a new instance of the DataServiceCollection<T> class.
public:
DataServiceCollection();
public DataServiceCollection ();
Public Sub New ()
注解
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 您可以创建 DataServiceCollection<T> 的实例,该实例在您使用可以为 None 提供 TrackingMode 值的构造函数创建实例时,会使用手动更改跟踪。You can create an instance of DataServiceCollection<T> that uses manual change tracking when you create an instance using a constructor that enables you to supply a value of None for TrackingMode. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
将项加载到集合中后,将开始自动更改跟踪。Automatic change tracking begins after items are loaded into the collection.
适用于
DataServiceCollection<T>(IEnumerable<T>)
创建基于查询执行的 DataServiceCollection<T> 类的新实例。Creates a new instance of the DataServiceCollection<T> class based on query execution.
public:
DataServiceCollection(System::Collections::Generic::IEnumerable<T> ^ items);
public DataServiceCollection (System.Collections.Generic.IEnumerable<T> items);
new System.Data.Services.Client.DataServiceCollection<'T> : seq<'T> -> System.Data.Services.Client.DataServiceCollection<'T>
Public Sub New (items As IEnumerable(Of T))
参数
- items
- IEnumerable<T>
DataServiceQuery<TElement> 或 LINQ 查询,可返回用于初始化集合的对象的 IEnumerable<T> 集合。A DataServiceQuery<TElement> or LINQ query that returns an IEnumerable<T> collection of objects that are used to initialize the collection.
注解
为 IEnumerable<T> 提供的对象的 items 集合通常是可一个返回集合中各项的查询。The IEnumerable<T> collection of objects supplied for items is usually a query that returns the items in the collection. 不过,可以提供正确类型的任何 IEnumerable<T> 集合。However, any IEnumerable<T> collection of the correct type can be supplied.
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 您可以创建 DataServiceCollection<T> 的实例,该实例在您使用可以为 None 提供 TrackingMode 值的构造函数创建实例时,会使用手动更改跟踪。You can create an instance of DataServiceCollection<T> that uses manual change tracking when you create an instance using a constructor that enables you to supply a value of None for TrackingMode. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
适用于
DataServiceCollection<T>(DataServiceContext)
创建 DataServiceCollection<T> 类的新实例,该实例使用指定的 DataServiceContext。Creates a new instance of the DataServiceCollection<T> class that uses the specified DataServiceContext.
public:
DataServiceCollection(System::Data::Services::Client::DataServiceContext ^ context);
public DataServiceCollection (System.Data.Services.Client.DataServiceContext context);
new System.Data.Services.Client.DataServiceCollection<'T> : System.Data.Services.Client.DataServiceContext -> System.Data.Services.Client.DataServiceCollection<'T>
Public Sub New (context As DataServiceContext)
参数
- context
- DataServiceContext
DataServiceContext 用于跟踪对集合中对象所做的更改。The DataServiceContext used to track changes to objects in the collection.
注解
使用此构造函数可创建空 DataServiceCollection<T>,在未对服务执行查询或 IEnumerable<T> 不可用时也可向其添加实体对象。Use this constructor to create an empty DataServiceCollection<T> to which entity objects can be added without executing a query against the service or when an IEnumerable<T> is not available.
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 您可以创建 DataServiceCollection<T> 的实例,该实例在您使用可以为 None 提供 TrackingMode 值的构造函数创建实例时,会使用手动更改跟踪。You can create an instance of DataServiceCollection<T> that uses manual change tracking when you create an instance using a constructor that enables you to supply a value of None for TrackingMode. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
适用于
DataServiceCollection<T>(IEnumerable<T>, TrackingMode)
创建基于查询执行并使用指定跟踪模式的 DataServiceCollection<T> 类的新实例。Creates a new instance of the DataServiceCollection<T> class based on query execution and with the specified tracking mode.
public:
DataServiceCollection(System::Collections::Generic::IEnumerable<T> ^ items, System::Data::Services::Client::TrackingMode trackingMode);
public DataServiceCollection (System.Collections.Generic.IEnumerable<T> items, System.Data.Services.Client.TrackingMode trackingMode);
new System.Data.Services.Client.DataServiceCollection<'T> : seq<'T> * System.Data.Services.Client.TrackingMode -> System.Data.Services.Client.DataServiceCollection<'T>
Public Sub New (items As IEnumerable(Of T), trackingMode As TrackingMode)
参数
- items
- IEnumerable<T>
DataServiceQuery<TElement> 或 LINQ 查询,可返回用于初始化集合的对象的 IEnumerable<T> 集合。A DataServiceQuery<TElement> or LINQ query that returns an IEnumerable<T> collection of objects that are used to initialize the collection.
- trackingMode
- TrackingMode
TrackingMode 值,用于指示是否自动跟踪对集合中各项所做的更改。A TrackingMode value that indicated whether or not changes made to items in the collection are automatically tracked.
注解
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 使用此类构造函数并为 None 提供 trackingMode 值,以便创建使用手动更改跟踪的 DataServiceCollection<T> 实例。Use this class constructor and supply a value of None for trackingMode to create an instance of DataServiceCollection<T> that uses manual change tracking. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
为 IEnumerable<T> 提供的对象的 items 集合通常是可一个返回集合中各项的查询。The IEnumerable<T> collection of objects supplied for items is usually a query that returns the items in the collection. 不过,可以提供正确类型的任何 IEnumerable<T> 集合。However, any IEnumerable<T> collection of the correct type can be supplied.
适用于
DataServiceCollection<T>(DataServiceContext, String, Func<EntityChangedParams,Boolean>, Func<EntityCollectionChangedParams,Boolean>)
创建使用所提供更改方法委托并使用指定的 DataServiceCollection<T> 的 DataServiceContext 类的新实例。Creates a new instance of the DataServiceCollection<T> class with the supplied change method delegates and that uses the specified DataServiceContext.
public:
DataServiceCollection(System::Data::Services::Client::DataServiceContext ^ context, System::String ^ entitySetName, Func<System::Data::Services::Client::EntityChangedParams ^, bool> ^ entityChangedCallback, Func<System::Data::Services::Client::EntityCollectionChangedParams ^, bool> ^ collectionChangedCallback);
public DataServiceCollection (System.Data.Services.Client.DataServiceContext context, string entitySetName, Func<System.Data.Services.Client.EntityChangedParams,bool> entityChangedCallback, Func<System.Data.Services.Client.EntityCollectionChangedParams,bool> collectionChangedCallback);
new System.Data.Services.Client.DataServiceCollection<'T> : System.Data.Services.Client.DataServiceContext * string * Func<System.Data.Services.Client.EntityChangedParams, bool> * Func<System.Data.Services.Client.EntityCollectionChangedParams, bool> -> System.Data.Services.Client.DataServiceCollection<'T>
Public Sub New (context As DataServiceContext, entitySetName As String, entityChangedCallback As Func(Of EntityChangedParams, Boolean), collectionChangedCallback As Func(Of EntityCollectionChangedParams, Boolean))
参数
- context
- DataServiceContext
DataServiceContext 用于跟踪集合中的项。The DataServiceContext used to track items in the collection.
- entitySetName
- String
集合中的对象实体集。The entity set of the objects in the collection.
- entityChangedCallback
- Func<EntityChangedParams,Boolean>
一种委托,用于封装在实体更改时进行调用的方法。A delegate that encapsulates a method that is called when an entity changes.
- collectionChangedCallback
- Func<EntityCollectionChangedParams,Boolean>
一种委托,用于封装在实体集合更改时进行调用的方法。A delegate that encapsulates a method that is called when the collection of entities changes.
注解
使用此构造函数可创建空 DataServiceCollection<T>,在未对服务执行查询或 IEnumerable<T> 不可用时也可向其添加实体对象。Use this constructor to create an empty DataServiceCollection<T> to which entity objects can be added without executing a query against the service or when an IEnumerable<T> is not available.
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 您可以创建 DataServiceCollection<T> 的实例,该实例在您使用可以为 None 提供 TrackingMode 值的构造函数创建实例时,会使用手动更改跟踪。You can create an instance of DataServiceCollection<T> that uses manual change tracking when you create an instance using a constructor that enables you to supply a value of None for TrackingMode. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
适用于
DataServiceCollection<T>(IEnumerable<T>, TrackingMode, String, Func<EntityChangedParams,Boolean>, Func<EntityCollectionChangedParams,Boolean>)
创建基于查询执行并使用所提供更改方法委托的 DataServiceCollection<T> 类的新实例。Creates a new instance of the DataServiceCollection<T> class a based on query execution and with the supplied change method delegates.
public:
DataServiceCollection(System::Collections::Generic::IEnumerable<T> ^ items, System::Data::Services::Client::TrackingMode trackingMode, System::String ^ entitySetName, Func<System::Data::Services::Client::EntityChangedParams ^, bool> ^ entityChangedCallback, Func<System::Data::Services::Client::EntityCollectionChangedParams ^, bool> ^ collectionChangedCallback);
public DataServiceCollection (System.Collections.Generic.IEnumerable<T> items, System.Data.Services.Client.TrackingMode trackingMode, string entitySetName, Func<System.Data.Services.Client.EntityChangedParams,bool> entityChangedCallback, Func<System.Data.Services.Client.EntityCollectionChangedParams,bool> collectionChangedCallback);
new System.Data.Services.Client.DataServiceCollection<'T> : seq<'T> * System.Data.Services.Client.TrackingMode * string * Func<System.Data.Services.Client.EntityChangedParams, bool> * Func<System.Data.Services.Client.EntityCollectionChangedParams, bool> -> System.Data.Services.Client.DataServiceCollection<'T>
Public Sub New (items As IEnumerable(Of T), trackingMode As TrackingMode, entitySetName As String, entityChangedCallback As Func(Of EntityChangedParams, Boolean), collectionChangedCallback As Func(Of EntityCollectionChangedParams, Boolean))
参数
- items
- IEnumerable<T>
DataServiceQuery<TElement> 或 LINQ 查询,可返回用于初始化集合的对象的 IEnumerable<T> 集合。A DataServiceQuery<TElement> or LINQ query that returns an IEnumerable<T> collection of objects that are used to initialize the collection.
- trackingMode
- TrackingMode
TrackingMode 值,用于指示是否自动跟踪对集合中各项所做的更改。A TrackingMode value that indicated whether or not changes made to items in the collection are automatically tracked.
- entitySetName
- String
集合中的对象实体集。The entity set of the objects in the collection.
- entityChangedCallback
- Func<EntityChangedParams,Boolean>
一种委托,用于封装在实体更改时进行调用的方法。A delegate that encapsulates a method that is called when an entity changes.
- collectionChangedCallback
- Func<EntityCollectionChangedParams,Boolean>
一种委托,用于封装在实体集合更改时进行调用的方法。A delegate that encapsulates a method that is called when the collection of entities changes.
注解
entityChanged 和 collectionChanged 函数分别由 PropertyChanged 和 CollectionChanged 事件调用。The entityChanged and collectionChanged functions are invoked by the PropertyChanged and CollectionChanged events, respectively. entityChanged 方法使用 EntityCollectionChangedParams 值,而 collectionChanged 方法则使用 EntityChangedParams 值。The entityChanged method takes an EntityCollectionChangedParams value and the collectionChanged method takes a EntityChangedParams value. 这两个方法都必须返回指示事件是否由函数进行处理的布尔值。Both methods must return a Boolean value that indicates whether the event was handled by the function. 当该方法返回时 true ,默认行为仍将出现。When the method returns true, the default behavior still occurs.
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 您可以创建 DataServiceCollection<T> 的实例,该实例在您使用可以为 None 提供 TrackingMode 值的构造函数创建实例时,会使用手动更改跟踪。You can create an instance of DataServiceCollection<T> that uses manual change tracking when you create an instance using a constructor that enables you to supply a value of None for TrackingMode. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
适用于
DataServiceCollection<T>(DataServiceContext, IEnumerable<T>, TrackingMode, String, Func<EntityChangedParams,Boolean>, Func<EntityCollectionChangedParams,Boolean>)
创建基于查询执行、使用所提供的更改方法委托并使用所提供的 DataServiceCollection<T> 的 DataServiceContext 类的新实例。Creates a new instance of the DataServiceCollection<T> class a based on query execution, with the supplied change method delegates, and that uses the supplied DataServiceContext.
public:
DataServiceCollection(System::Data::Services::Client::DataServiceContext ^ context, System::Collections::Generic::IEnumerable<T> ^ items, System::Data::Services::Client::TrackingMode trackingMode, System::String ^ entitySetName, Func<System::Data::Services::Client::EntityChangedParams ^, bool> ^ entityChangedCallback, Func<System::Data::Services::Client::EntityCollectionChangedParams ^, bool> ^ collectionChangedCallback);
public DataServiceCollection (System.Data.Services.Client.DataServiceContext context, System.Collections.Generic.IEnumerable<T> items, System.Data.Services.Client.TrackingMode trackingMode, string entitySetName, Func<System.Data.Services.Client.EntityChangedParams,bool> entityChangedCallback, Func<System.Data.Services.Client.EntityCollectionChangedParams,bool> collectionChangedCallback);
new System.Data.Services.Client.DataServiceCollection<'T> : System.Data.Services.Client.DataServiceContext * seq<'T> * System.Data.Services.Client.TrackingMode * string * Func<System.Data.Services.Client.EntityChangedParams, bool> * Func<System.Data.Services.Client.EntityCollectionChangedParams, bool> -> System.Data.Services.Client.DataServiceCollection<'T>
Public Sub New (context As DataServiceContext, items As IEnumerable(Of T), trackingMode As TrackingMode, entitySetName As String, entityChangedCallback As Func(Of EntityChangedParams, Boolean), collectionChangedCallback As Func(Of EntityCollectionChangedParams, Boolean))
参数
- context
- DataServiceContext
DataServiceContext 用于跟踪集合中的项。The DataServiceContext used to track items in the collection.
- items
- IEnumerable<T>
DataServiceQuery<TElement> 或 LINQ 查询,可返回用于初始化集合的对象的 IEnumerable<T> 集合。A DataServiceQuery<TElement> or LINQ query that returns an IEnumerable<T> collection of objects that are used to initialize the collection.
- trackingMode
- TrackingMode
TrackingMode 值,用于指示是否自动跟踪对集合中各项所做的更改。A TrackingMode value that indicated whether or not changes made to items in the collection are automatically tracked.
- entitySetName
- String
集合中的对象实体集。The entity set of the objects in the collection.
- entityChangedCallback
- Func<EntityChangedParams,Boolean>
一种委托,用于封装在实体更改时进行调用的方法。A delegate that encapsulates a method that is called when an entity changes.
- collectionChangedCallback
- Func<EntityCollectionChangedParams,Boolean>
一种委托,用于封装在实体集合更改时进行调用的方法。A delegate that encapsulates a method that is called when the collection of entities changes.
注解
默认情况下,将对 DataServiceCollection<T> 启用自动更改跟踪。By default, automatic change tracking is enabled for a DataServiceCollection<T>. 使用此类构造函数为 None 提供 trackingMode 值,以便创建使用手动更改跟踪的 DataServiceCollection<T> 实例。Use this class constructor to supply a value of None for trackingMode to create an instance of DataServiceCollection<T> that uses manual change tracking. 使用手动跟踪时,必须实现 INotifyPropertyChanged 和 INotifyCollectionChanged 并处理引发事件,以便将更改手动报告到 DataServiceContext。When you use manual tracking, you must implement INotifyPropertyChanged and INotifyCollectionChanged and handle the raise events to manually report changes to the DataServiceContext.
当 DataServiceContext 不是引用了 items 实例的 DataServiceQuery<TElement> 或 QueryOperationResponse<T> 时,必须提供 DataServiceContext。The DataServiceContext must be supplied when items is not a DataServiceQuery<TElement> or QueryOperationResponse<T> that has a reference to a DataServiceContext instance.
entityChanged 和 collectionChanged 函数分别由 PropertyChanged 和 CollectionChanged 事件调用。The entityChanged and collectionChanged functions are invoked by the PropertyChanged and CollectionChanged events, respectively. entityChanged 方法使用 EntityCollectionChangedParams 值,而 collectionChanged 方法则使用 EntityChangedParams 值。The entityChanged method takes an EntityCollectionChangedParams value and the collectionChanged method takes a EntityChangedParams value. 这两个方法都必须返回指示事件是否由函数进行处理的布尔值。Both methods must return a Boolean value that indicates whether the event was handled by the function. 当该方法返回时 true ,默认行为仍将出现。When the method returns true, the default behavior will still occur.