Share via


RequestOptions.AccessCondition Property

Definition

Gets or sets the condition (ETag) associated with the request in the Azure Cosmos DB service.

public Microsoft.Azure.Documents.Client.AccessCondition AccessCondition { get; set; }
member this.AccessCondition : Microsoft.Azure.Documents.Client.AccessCondition with get, set
Public Property AccessCondition As AccessCondition

Property Value

The condition (ETag) associated with the request.

Examples

The following example shows how to use RequestOptions with ReplaceDocumentAsync(String, Object, RequestOptions, CancellationToken) to specify the set of AccessCondition to be used when updating a document

// If ETag is current, then this will succeed. Otherwise the request will fail with HTTP 412 Precondition Failure
await client.ReplaceDocumentAsync(
    readCopyOfBook.SelfLink,
    new Book { Title = "Moby Dick", Price = 14.99 },
    new RequestOptions
    {
        AccessCondition = new AccessCondition
        {
            Condition = readCopyOfBook.ETag,
            Type = AccessConditionType.IfMatch
        }
     });

Remarks

Most commonly used with the Delete* and Replace* methods of DocumentClient such as ReplaceDocumentAsync(Document, RequestOptions, CancellationToken) or ReplaceDocumentAsync(String, Object, RequestOptions, CancellationToken) methods, but can be used with other methods like ReadDocumentAsync(String, RequestOptions, CancellationToken) for caching scenarios.

Applies to