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

✨ [FEATURE] UnitOfWork --> EfCore Transactions and Rollbacks? #20

Closed
jeffward01 opened this issue Oct 1, 2022 · 3 comments
Closed
Assignees
Labels
enhancement New feature or request

Comments

@jeffward01
Copy link

Summary

I am not sure if there is a reason why this is not implemented, perhaps you have done some tests and its not as simple as it looks.

Is there any reason why Transactions and Rollback is not implemented?

Is this something that you'd like me to add?

Is there any particular feature or way you would like this to be implemented?

Reading

@jeffward01 jeffward01 added the enhancement New feature or request label Oct 1, 2022
@furkandeveloper
Copy link
Owner

UnitOfWork works with all or nothing logic.

Managing transactions is one method. However, no update or add method will be committed to the database without savechange running.
Users have to call UnitOfWork.Repository.Complete method because savechanges will not work without the Complete method in scope.

Supports EF Core Change Tracker feature. Tries to apply all changes to the context. If he gets an error on any of them, he can't perform any action anyway.

@jeffward01
Copy link
Author

jeffward01 commented Oct 1, 2022

I respect that this is closed, and your explanation makes sense.


I am curious as to why Microsoft has a TransactionScope and a Rollback ability in this case?

I think this is more of an EfCore question, if you have time can you help me understand why this is the case?

For Example:

https://stackoverflow.com/questions/53324601/transaction-scope-for-different-repository-classes

public PizzaService(IDbContextScopeFactory contextScopeFactory, IPizzaRepo pizzaRepo, IPizzaIngredientsRepo ingredientRepo)
{
  _contextScopeFactory = contextScopeFactory;
  _pizzaRepo = pizzaRepo;
  _ingredientRepo = ingredientRepo;
}

public async Task SavePizza(PizzaViewModel pizza)
{
  using (var contextScope = _contextScopeFactory.Create())
  {
    int pizzaRows = await _pizzaRepo.AddEntityAsync(pizza.Pizza);
    int ingredientRows = await _ingredientRepo.PutIngredientsOnPizza(
      pizza.Pizza.PizzaId,
      pizza.Ingredients.Select(x => x.IngredientId).ToArray());

    contextScope.SaveChanges();
  }
}  

What is the advantage of the TransactionScope if its truly an 'all or nothing' logic?

@furkandeveloper
Copy link
Owner

furkandeveloper commented Oct 1, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants