DataServiceContext.AttachTo Method (String, Object, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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:  System.Data.Services.Client (in System.Data.Services.Client.dll)

public void AttachTo(
	string entitySetName,
	object entity,
	string etag


Type: System.String

The string value that contains the name of the entity set to which to the entity is attached.

Type: System.Object

The entity to add.

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.

Exception Condition

When entitySetName is null.


When entity is null.


When entitySetName is an empty string.


When the supplied object does not have a key property.


When the supplied object is already being tracked by the context

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.

.NET Framework
Available since 3.5
Available since 2.0
Return to top