This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.Cosmos; | |
using var client = new CosmosClient("AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw=="); | |
var container = client.GetContainer("demo", "orders"); | |
var newOrder = new Order | |
{ | |
Id = Guid.NewGuid().ToString(), | |
CustomerId = "CodeOpinion" | |
}; | |
await container.CreateItemAsync(newOrder, new PartitionKey(newOrder.Id)); | |
var readOrder = await container.ReadItemAsync<Order>(newOrder.Id, new PartitionKey(newOrder.Id)); | |
readOrder.Resource.Status = OrderStatus.Processing; | |
// Works because ETag is correct | |
await container.UpsertItemAsync(readOrder.Resource, new PartitionKey(readOrder.Resource.Id), new ItemRequestOptions | |
{ | |
IfMatchEtag = readOrder.ETag, | |
}); | |
// Fails because ETag was changed when Upsert occured above. | |
await container.UpsertItemAsync(readOrder.Resource, new PartitionKey(readOrder.Resource.Id), new ItemRequestOptions | |
{ | |
IfMatchEtag = readOrder.ETag, | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment