DocumentClient.ReplaceDocumentAsync メソッド

定義

オーバーロード

ReplaceDocumentAsync(Document, RequestOptions, CancellationToken)

Document Azure Cosmos DB サービス内の を非同期操作として置き換えます。

ReplaceDocumentAsync(String, Object, RequestOptions, CancellationToken)

Document Azure Cosmos DB サービス内の を非同期操作として置き換えます。

ReplaceDocumentAsync(Uri, Object, RequestOptions, CancellationToken)

ドキュメントを Azure Cosmos DB サービスの非同期操作として置き換えます。

ReplaceDocumentAsync(Document, RequestOptions, CancellationToken)

Document Azure Cosmos DB サービス内の を非同期操作として置き換えます。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> ReplaceDocumentAsync (Microsoft.Azure.Documents.Document document, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceDocumentAsync : Microsoft.Azure.Documents.Document * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
override this.ReplaceDocumentAsync : Microsoft.Azure.Documents.Document * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
Public Function ReplaceDocumentAsync (document As Document, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Document))

パラメーター

document
Document

既存のリソースを に置き換える更新。Document

options
RequestOptions

(省略可能)要求の要求オプション。

cancellationToken
CancellationToken

(省略可能) CancellationToken 取り消しの通知を受け取るために他のオブジェクトまたはスレッドが使用できる 。

戻り値

System.Threading.Tasks更新されたリソース レコードをResourceResponse<TResource>含む をDocumentラップする を含む 。

実装

例外

が設定されていない場合 document

この例外により、さまざまな種類のエラーがカプセル化される可能性があります。 特定のエラーを特定するには、常に StatusCode プロパティを参照してください。 ドキュメントの作成時に取得できる一般的なコードは次のとおりです。

StatusCode例外の理由
404NotFound - 削除しようとしたリソースが存在しなかったことを意味します。

この例では、 を使用 Document し、動的オブジェクトであるという事実を利用し、SetProperty を使用してドキュメントのプロパティを動的に更新します

//Fetch the Document to be updated
Document doc = client.CreateDocumentQuery<Document>(collectionLink)
                            .Where(r => r.Id == "doc id")
                            .AsEnumerable()
                            .SingleOrDefault();

//Update some properties on the found resource
doc.SetPropertyValue("MyProperty", "updated value");

//Now persist these changes to the database by replacing the original resource
Document updated = await client.ReplaceDocumentAsync(doc);

こちらもご覧ください

適用対象

ReplaceDocumentAsync(String, Object, RequestOptions, CancellationToken)

Document Azure Cosmos DB サービス内の を非同期操作として置き換えます。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> ReplaceDocumentAsync (string documentLink, object document, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceDocumentAsync : string * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
override this.ReplaceDocumentAsync : string * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
Public Function ReplaceDocumentAsync (documentLink As String, document As Object, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Document))

パラメーター

documentLink
String

更新するドキュメントのリンク。 例: dbs/db_rid/colls/col_rid/docs/doc_rid/

document
Object

既存のリソースを に置き換える更新。Document

options
RequestOptions

(省略可能)要求の要求オプション。

cancellationToken
CancellationToken

(省略可能) CancellationToken 取り消しの通知を受け取るために他のオブジェクトまたはスレッドが使用できる 。

戻り値

System.Threading.Tasks更新されたリソース レコードをResourceResponse<TResource>含む をDocumentラップする を含む 。

実装

例外

または documentdocumentLink設定されていない場合。

この例外により、さまざまな種類のエラーがカプセル化される可能性があります。 特定のエラーを特定するには、常に StatusCode プロパティを参照してください。 ドキュメントの作成時に取得できる一般的なコードは次のとおりです。

StatusCode例外の理由
404NotFound - 削除しようとしたリソースが存在しなかったことを意味します。

この例では、厳密に型指定された Documentを使用する代わりに、独自の POCO オブジェクトを操作し、Document クラスの動的な性質に依存しません。

public class MyPoco
{
    public string Id {get; set;}
    public string MyProperty {get; set;}
}

//Get the doc back as a Document so you have access to doc.SelfLink
Document doc = client.CreateDocumentQuery<Document>(collectionLink)
                       .Where(r => r.Id == "doc id")
                       .AsEnumerable()
                       .SingleOrDefault();

//Now dynamically cast doc back to your MyPoco
MyPoco poco = (dynamic)doc;

//Update some properties of the poco object
poco.MyProperty = "updated value";

//Now persist these changes to the database using doc.SelLink and the update poco object
Document updated = await client.ReplaceDocumentAsync(doc.SelfLink, poco);

こちらもご覧ください

適用対象

ReplaceDocumentAsync(Uri, Object, RequestOptions, CancellationToken)

ドキュメントを Azure Cosmos DB サービスの非同期操作として置き換えます。

public System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>> ReplaceDocumentAsync (Uri documentUri, object document, Microsoft.Azure.Documents.Client.RequestOptions options = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReplaceDocumentAsync : Uri * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
override this.ReplaceDocumentAsync : Uri * obj * Microsoft.Azure.Documents.Client.RequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.Azure.Documents.Client.ResourceResponse<Microsoft.Azure.Documents.Document>>
Public Function ReplaceDocumentAsync (documentUri As Uri, document As Object, Optional options As RequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ResourceResponse(Of Document))

パラメーター

documentUri
Uri

更新するドキュメントの URI。

document
Object

更新されたドキュメント。

options
RequestOptions

要求の要求オプション。

cancellationToken
CancellationToken

(省略可能) CancellationToken 要求の取り消しを表します。

戻り値

非同期操作のサービス応答を表すタスク オブジェクト。

実装

適用対象