Code Monkey home page Code Monkey logo

Comments (3)

furkandeveloper avatar furkandeveloper commented on June 11, 2024 1

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.

from easyrepository.efcore.

jeffward01 avatar jeffward01 commented on June 11, 2024

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?

from easyrepository.efcore.

furkandeveloper avatar furkandeveloper commented on June 11, 2024

This resource will be useful to you. @jeffward01

https://stackoverflow.com/questions/50844828/ef-db-savechanges-vs-dbtransaction-commit

from easyrepository.efcore.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.