Поделиться через


DataServiceContext.AttachTo Method (String, Object, String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Notifies the DataServiceContext to start tracking the specified resource and supplies the location of the resource within the specified resource set.

Namespace:  System.Data.Services.Client
Assembly:  System.Data.Services.Client (in System.Data.Services.Client.dll)

Syntax

'Declaration
Public Sub AttachTo ( _
    entitySetName As String, _
    entity As Object, _
    etag As String _
)
public void AttachTo(
    string entitySetName,
    Object entity,
    string etag
)

Parameters

  • entitySetName
    Type: System.String
    The string value that contains the name of the entity set to which the entity is attached.
  • etag
    Type: System.String
    An eTag value that represents the state of the entity the last time that it was retrieved from the data service. This value is treated as an opaque string; no validation is performed on it by the client library.

Exceptions

Exception Condition
ArgumentNullException

When entity or entitySetName are nulla null reference (Nothing in Visual Basic).

ArgumentException

When entitySetName is an empty string.

-or-

When entity does not have a key property.

InvalidOperationException

When entity is already being tracked by the context.

Remarks

Calling this method notifies the DataServiceContext to start tracking the specified entity and identifies the entity set to which the entity belongs.

If the entity is part of an object graph, this operation does not traverse the graph to add related objects. The object is added to the DataServiceContext in the unchanged state. The method does not validate whether the specified entity set exists in the data service that is associated with the DataServiceContext.

If the overload with an eTag is used, the specified eTag is associated with the newly attached entity. The eTag is then sent to the data service, with all later update or query operations for the entity, according to HTTP semantics. Manual generation of eTag values is not recommended, but this overload is provided to allow entities that may have been serialized and stored to be reattached together with relevant concurrency metadata.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.