Skip to content

Instantly share code, notes, and snippets.

@ealsur
Created January 6, 2020 18:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ealsur/3d18f0cbc6258e8f27565a8581790e45 to your computer and use it in GitHub Desktop.
Save ealsur/3d18f0cbc6258e8f27565a8581790e45 to your computer and use it in GitHub Desktop.
TransactionalBatch - Error view
// Parent's birthday!
parent.Age = 31;
// Naming two childs with the same name, should abort the transaction
ChildClass anotherChild = new ChildClass(){ Id = "The Child", ParentId = parent.Id, PartitionKey = partitionKey };
TransactionalBatchResponse failedBatchResponse = await container.CreateTransactionalBatch(new PartitionKey(partitionKey))
.ReplaceItem<ParentClass>(parent.Id, parent)
.CreateItem<ChildClass>(anotherChild)
.ExecuteAsync();
using (failedBatchResponse)
{
if (!failedBatchResponse.IsSuccessStatusCode)
{
TransactionalBatchOperationResult<ParentClass> parentResult = failedBatchResponse.GetOperationResultAtIndex<ParentClass>(0);
// parentResult.StatusCode is 424
TransactionalBatchOperationResult<ChildClass> childResult = failedBatchResponse.GetOperationResultAtIndex<ChildClass>(1);
// childResult.StatusCode is 409
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment