DataServiceContext.AttachTo 方法 (String, Object, String)
通知 DataServiceContext 开始跟踪指定资源,并在指定资源集中提供该资源的位置。
命名空间: System.Data.Services.Client
程序集: Microsoft.Data.Services.Client(在 Microsoft.Data.Services.Client.dll 中)
语法
声明
Public Sub AttachTo ( _
entitySetName As String, _
entity As Object, _
etag As String _
)
用法
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
)
参数
- entitySetName
类型:System.String
包含实体所附加到的实体集名称的字符串值。
- entity
类型:System.Object
要添加的实体。
- etag
类型:System.String
一种 etag 值,表示上次从数据服务检索实体时该实体的状态。可将此值视为不透明的字符串;未通过客户端库对其执行任何验证。
异常
异常 | 条件 |
---|---|
ArgumentNullException | 当 entitySetName 为 nullnull 引用(在 Visual Basic 中为 Nothing) 时。 - 或 - 当 entity 为 nullnull 引用(在 Visual Basic 中为 Nothing) 时。 |
ArgumentException | 当 entitySetName 为空字符串时。 - 或 - 当所提供的对象不具有键属性时。 |
InvalidOperationException | 当所提供的对象已由上下文跟踪时 |
注释
调用此方法时,将通知 DataServiceContext 开始跟踪指定实体,并标识该实体所属的实体集。
如果实体为对象图的一部分,则此操作不会遍历该图来添加相关对象。 对象将在未更改状态下添加到 DataServiceContext。 该方法不会验证指定的实体集是否出现在与 DataServiceContext 关联的数据服务中。
如果使用了带 etag 的重载,则指定的 etag 将与新附加的实体相关联。 然后,根据 HTTP 语义,将 etag 发送到提供该实体所有后续更新或查询操作的数据服务。 建议不要手动生成 etag 值,但可提供此重载以启用实体,这些实体可能已序列化并已进行存储,目的是将其与相关并发元数据重新附加到一起。