You are developing a .NET application using the Azure Cosmos DB .NET SDK v3 to manage configuration settings for smart electricity meters. The container uses `/meterId` as its partition key.
You need to write a method that updates a meter's configuration status (updating an existing item) and creates a status transition audit log entry (creating a new item) for the same meter. Both operations must succeed or fail together as a single atomic unit. You must also implement Optimistic Concurrency Control (OCC) for the status update to prevent overwriting concurrent updates.
You have the following partially completed method:
csharp
public async Task<bool> UpdateMeterStatusAndLogAsync(
Container container,
string meterId,
MeterStatus updatedStatus,
string expectedETag)
{
// Initialize the transactional batch
// Add the status update operation using OCC
// (Remaining operations to add the audit log and execute the batch are implemented elsewhere)
}
Which two code segments should you use to perform these actions? (Select two.)
- TransactionalBatch batch = container.CreateTransactionalBatch(new PartitionKey(meterId));Answer
- batch.ReplaceItem<MeterStatus>(meterId, updatedStatus, new TransactionalBatchItemRequestOptions { IfMatchEtag = expectedETag });Answer
- CTransactionalBatch batch = container.CreateTransactionalBatch(meterId);
- Dbatch.ReplaceItem<MeterStatus>(meterId, updatedStatus, new ItemRequestOptions { IfMatchEtag = expectedETag });
- Ebatch.ReplaceItem<MeterStatus>(updatedStatus, meterId, new PartitionKey(meterId), new TransactionalBatchItemRequestOptions { IfMatchEtag = expectedETag });