You are developing a C# service that manages smart-home IoT devices using the Azure Cosmos DB .NET SDK v3. The container stores configuration settings and is partitioned by the `/deviceId` path. The database uses Session consistency. When a device's settings are updated, your service must replace the existing document, retrieve the resulting session token to pass to other reading clients, and ensure the write operation is routed to the correct partition. Which C# code segment should you use?
- ItemResponse<DeviceConfig> response = await container.ReplaceItemAsync<DeviceConfig>(config, config.Id, new PartitionKey(config.DeviceId));
string sessionToken = response.Headers.Session;Cevap - BItemResponse<DeviceConfig> response = await container.ReplaceItemAsync<DeviceConfig>(config, config.Id, new PartitionKey(config.Id));
string sessionToken = response.Headers.Session; - CItemResponse<DeviceConfig> response = await container.ReplaceItemAsync<DeviceConfig>(config, config.Id, new PartitionKey("all-devices"));
string sessionToken = response.Headers.Session; - DItemResponse<DeviceConfig> response = await container.ReplaceItemAsync<DeviceConfig>(config, config.Id, new PartitionKey(config.DeviceId));
string sessionToken = response.RequestCharge.ToString();
Cevap
The correct option is the one that calls ReplaceItemAsync using config.Id and a PartitionKey instantiated with config.DeviceId, and then retrieves the session token using response.Headers.Session.
The correct code segment uses the ReplaceItemAsync method of the Container class to update the item. It correctly passes the unique document ID and a PartitionKey initialized with the deviceId. The session token is then successfully extracted from the Headers.Session property of the ItemResponse object.
Adım Adım Çözüm
Anahtar Kavram
Replacing items in Azure Cosmos DB using the .NET SDK v3 and capturing the Session consistency token.
Tahmini Süre:1m 30s