You are developing a C# backend service that manages customer order logs using the Azure Cosmos DB .NET SDK v3. The Cosmos DB container uses Session consistency and is partitioned by the customer's identifier (/customerId). A different client session has just created a new order log item with the ID "order-789" for the customer "customer-101". Your service must perform a point read to retrieve this new log item immediately, ensuring it reads the latest write. Which C# code segment should you use?
- string sessionToken = GetWriterSessionToken();
ItemRequestOptions options = new ItemRequestOptions { SessionToken = sessionToken };
ItemResponse<OrderLog> response = await container.ReadItemAsync<OrderLog>("order-789", new PartitionKey("customer-101"), options);Answer - BItemResponse<OrderLog> response = await container.ReadItemAsync<OrderLog>("order-789", new PartitionKey("customer-101"));
- Cstring sessionToken = GetWriterSessionToken();
ItemRequestOptions options = new ItemRequestOptions { SessionToken = sessionToken };
ItemResponse<OrderLog> response = await container.ReadItemAsync<OrderLog>("order-789", new PartitionKey("completed"), options); - Dstring sessionToken = GetWriterSessionToken();
ItemRequestOptions options = new ItemRequestOptions { SessionToken = sessionToken };
ItemResponse<OrderLog> response = await container.ReadItemAsync<OrderLog>("order-789", PartitionKey.None, options);
Answer
The correct option is the one that retrieves the write session token, configures it in ItemRequestOptions, and passes both the item ID and the customer-101 partition key to ReadItemAsync.
The correct option obtains the session token from the write operation, configures it in ItemRequestOptions, and calls ReadItemAsync with the item ID and the partition key containing the customer identifier. Under Azure Cosmos DB's Session consistency, sharing the session token is required to guarantee read-your-writes consistency across different client sessions.
Step-by-Step Solution
Key Concept
Session consistency requires passing the session token across different client sessions to guarantee read-your-writes consistency during item operations.