共用方式為


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
    字串值,包含實體附加至的實體集名稱。
  • etag
    型別:System.String
    etag 值,表示上次從資料服務擷取時的實體狀態。此值被視為不透明的字串;用戶端程式庫不會對它執行任何驗證。

例外狀況

例外狀況 條件
ArgumentNullException

當 entitySetName 為 nullnull 參考 (在 Visual Basic 中為 Nothing) 時。

-或-

當 entity 為 nullnull 參考 (在 Visual Basic 中為 Nothing) 時。

ArgumentException

當 entitySetName 是空字串時。

-或-

當提供的物件沒有索引鍵屬性時。

InvalidOperationException

當提供的物件已經受到內容追蹤時

備註

呼叫這個方法會通知 DataServiceContext,開始追蹤指定的實體並識別該實體所屬的實體集。

如果實體是物件圖形的一部分,這項作業不會周遊該圖形以加入相關物件。 物件是以未變更狀態加入 DataServiceContext。 此方法不會驗證與 DataServiceContext 相關聯的資料服務中是否發生指定的實體集。

如果使用有 etag 的多載,則會使指定的 etag 與新附加的實體產生關聯。 於是,etag 就會根據 HTTP 語意隨著實體的所有後續更新或查詢作業傳送至資料服務。 不建議手動產生 etag 值,提供此多載是為了讓可能已序列化並儲存的實體連同相關並行中繼資料重新附加。

請參閱

參考

DataServiceContext 類別

AttachTo 多載

System.Data.Services.Client 命名空間