DataServiceContext.AttachTo 方法

定义

通知 DataServiceContext 开始跟踪指定的资源,并提供指定资源集中资源的位置。

重载

名称 说明
AttachTo(String, Object)

通知 DataServiceContext 开始跟踪指定的资源,并提供指定资源集中资源的位置。

AttachTo(String, Object, String)

通知 DataServiceContext 开始跟踪指定的资源,并提供指定资源集中资源的位置。

AttachTo(String, Object)

通知 DataServiceContext 开始跟踪指定的资源,并提供指定资源集中资源的位置。

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)

参数

entitySetName
String

包含资源的集的名称。

entity
Object

要由 . DataServiceContext. 跟踪的资源。 资源以“未更改”状态附加。

例外

entityentitySetNamenull.

entitySetName 是空字符串。

-或-

entity 未定义键属性。

entity 已由上下文跟踪。

注解

如果实体是对象图的一部分,此操作不会遍历图形以添加相关对象。 这是一个浅表操作。

该方法不验证指定的实体集是否发生在与 。

适用于

AttachTo(String, Object, String)

通知 DataServiceContext 开始跟踪指定的资源,并提供指定资源集中资源的位置。

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)

参数

entitySetName
String

包含附加到实体的实体集名称的字符串值。

entity
Object

要添加的实体。

etag
String

一个 etag 值,表示上次从数据服务检索实体的状态。 此值被视为不透明字符串;客户端库不会对它执行任何验证。

例外

entitySetNamenull

-或-

entitynull

entitySetName 是空字符串。

-或-

提供的对象没有键属性。

提供的对象已被上下文跟踪。

注解

调用此方法会通知 DataServiceContext 开始跟踪指定的实体,并标识实体所属的实体集。

如果实体是对象图的一部分,此操作不会遍历图形以添加相关对象。 对象将添加到 DataServiceContext 未更改状态。 该方法不验证指定的实体集是否发生在与 。

如果使用具有 etag 的重载,则指定的 etag 与新附加的实体相关联。 然后,etag 将发送到数据服务,并按照 HTTP 语义对实体执行所有后续更新或查询操作。 不建议手动生成 etag 值,但提供了此重载,使可能已序列化并存储的实体与相关的并发元数据一起重新附加。

适用于