Share via


DataServiceContext.AttachTo Method (String, Object, String)

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

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

Syntax

'Declaration
Public Sub AttachTo ( _
    entitySetName As String, _
    entity As Object, _
    etag As String _
)
'Usage
Dim instance As DataServiceContext 
Dim entitySetName As String 
Dim entity As Object 
Dim etag As String

instance.AttachTo(entitySetName, entity, _
    etag)
public void AttachTo(
    string entitySetName,
    Object entity,
    string etag
)
public:
void AttachTo(
    String^ entitySetName, 
    Object^ entity, 
    String^ etag
)
member AttachTo : 
        entitySetName:string * 
        entity:Object * 
        etag:string -> unit
public function AttachTo(
    entitySetName : String, 
    entity : Object, 
    etag : String
)

Parameters

  • entitySetName
    Type: System.String
    The string value that contains the name of the entity set to which to the entity is attached.
  • etag
    Type: System.String
    An etag value that represents the state of the entity the last time 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 entitySetName is nulla null reference (Nothing in Visual Basic).

-or-

When entity is nulla null reference (Nothing in Visual Basic).

ArgumentException

When entitySetName is an empty string.

-or-

When the supplied object does not have a key property.

InvalidOperationException

When the supplied object 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 entity set specified occurs in the data service 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 subsequent 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 enable entities that may have been serialized and stored to be reattached together with relevant concurrency metadata.

See Also

Reference

DataServiceContext Class

AttachTo Overload

System.Data.Services.Client Namespace