Share via


CosmosContainer.DeleteItemAsync<T> Method

Definition

Delete a item from the Azure Cosmos service as an asynchronous operation.

public abstract System.Threading.Tasks.Task<Azure.Cosmos.ItemResponse<T>> DeleteItemAsync<T> (string id, Azure.Cosmos.PartitionKey partitionKey, Azure.Cosmos.ItemRequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member DeleteItemAsync : string * Azure.Cosmos.PartitionKey * Azure.Cosmos.ItemRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Cosmos.ItemResponse<'T>>
Public MustOverride Function DeleteItemAsync(Of T) (id As String, partitionKey As PartitionKey, Optional requestOptions As ItemRequestOptions = Nothing, Optional cancellationToken As CancellationToken = Nothing) As Task(Of ItemResponse(Of T))

Type Parameters

T

Parameters

id
String

The cosmos item id

partitionKey
PartitionKey

The partition key for the item. PartitionKey

requestOptions
ItemRequestOptions

(Optional) The options for the item request ItemRequestOptions

cancellationToken
CancellationToken

(Optional) CancellationToken representing request cancellation.

Returns

A Task containing a Response<T> which will contain information about the request issued.

Exceptions

This exception can encapsulate many different types of errors. To determine the specific error always look at the StatusCode property. Some common codes you may get when creating a Document are:

StatusCodeReason for exception
429TooManyRequests - This means you have exceeded the number of request units per second.

Examples

public class ToDoActivity{
    public string id {get; set;}
    public string status {get; set;}
}

ItemResponse item = await this.container.DeleteItemAsync<ToDoActivity>("partitionKey", "id");

Applies to