Redigera

Dela via


DataServiceContext.AttachTo Method

Definition

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

Overloads

AttachTo(String, Object)

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

AttachTo(String, Object, String)

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

AttachTo(String, Object)

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

public:
 void AttachTo(System::String ^ entitySetName, System::Object ^ entity);
public void AttachTo (string entitySetName, object entity);
member this.AttachTo : string * obj -> unit
Public Sub AttachTo (entitySetName As String, entity As Object)

Parameters

entitySetName
String

The name of the set that contains the resource.

entity
Object

The resource to be tracked by the DataServiceContext. The resource is attached in the Unchanged state.

Exceptions

entity or entitySetName is null.

entitySetName is an empty string.

-or-

entity does not have a key property defined.

entity is already being tracked by the context.

Remarks

If the entity is part of an object graph, this operation does not traverse the graph to add related objects. It is a shallow operation.

The method does not validate whether the specified entity set occurs in the data service associated with the DataServiceContext.

Applies to

AttachTo(String, Object, String)

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

public:
 void AttachTo(System::String ^ entitySetName, System::Object ^ entity, System::String ^ etag);
public void AttachTo (string entitySetName, object entity, string etag);
member this.AttachTo : string * obj * string -> unit
Public Sub AttachTo (entitySetName As String, entity As Object, etag As String)

Parameters

entitySetName
String

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

entity
Object

The entity to add.

etag
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

entitySetName is null.

-or-

entity is null.

entitySetName is an empty string.

-or-

The supplied object does not have a key property.

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.

Applies to