Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactional Batch support for CosmosDB in EF Core #23364

Closed
rmaziarka opened this issue Nov 17, 2020 · 1 comment
Closed

Transactional Batch support for CosmosDB in EF Core #23364

rmaziarka opened this issue Nov 17, 2020 · 1 comment

Comments

@rmaziarka
Copy link

Currently, there is an option to save objects to the CosmosDB in transaction using Transactional Batch

string partitionKey = "The Family";

ParentClass parent = new ParentClass(){ Id = "The Parent", PartitionKey = partitionKey, Name = "John", Age = 30 }; 
ChildClass child = new ChildClass(){ Id = "The Child", ParentId = parent.Id, PartitionKey = partitionKey }; 

TransactionalBatch batch = container.CreateTransactionalBatch(new PartitionKey(parent.PartitionKey)) 
  .CreateItem<ParentClass>(parent) 
  .CreateItem<ChildClass>(child);

TransactionalBatchResponse batchResponse = await batch.ExecuteAsync();

Unfortunately, when I tried to switch to EF Core I realized that context's SaveChangesAsync doesn't use TransactionalBatch and therefore it saves entities separately.

It is a problem in a situation when we change one entity and add another one:

  • Book entity is blocked
  • Reservation entity is created
    When updating the Book entity fails because of ETag concurrency, creating the Reservation entity succeeds and we end up with an invalid state.

Would it be possible to introduce TransactionalBatch functionality to EF Core?

@AndriySvyryd
Copy link
Member

Duplicate of #17308

@AndriySvyryd AndriySvyryd marked this as a duplicate of #17308 Nov 19, 2020
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants