CosmosContainer.ReadItemAsync<T> Method

Definition

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

public abstract System.Threading.Tasks.Task<Azure.Cosmos.ItemResponse<T>> ReadItemAsync<T> (string id, Azure.Cosmos.PartitionKey partitionKey, Azure.Cosmos.ItemRequestOptions requestOptions = default, System.Threading.CancellationToken cancellationToken = default);
abstract member ReadItemAsync : string * Azure.Cosmos.PartitionKey * Azure.Cosmos.ItemRequestOptions * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Cosmos.ItemResponse<'T>>
Public MustOverride Function ReadItemAsync(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 wraps the read resource record.

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;}
}

ToDoActivity toDoActivity = await this.container.ReadItemAsync<ToDoActivity>("id", new PartitionKey("partitionKey"));

Remarks

Items contain meta data that can be obtained by mapping these meta data attributes to properties in T. * "_ts": Gets the last modified time stamp associated with the item from the Azure Cosmos DB service. * "_etag": Gets the entity tag associated with the item from the Azure Cosmos DB service. * "ttl": Gets the time to live in seconds of the item in the Azure Cosmos DB service.

Applies to