Open Closed

The CompleteAsync method does not work when isRequired is set to false #5079


User avatar
0
ademaygun created
  • ABP Framework version: v5.3.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): no
  • Exception message and stack trace:
  • Steps to reproduce the issue:"

I am debugging the code below. When I check the database after executing the CompleteAsync() command, I observe that there is no change. The change only occurs when the method is completed. Don't you think this is misleading?

public async Task UpdateAsync(string name)
        {
            List<string> myList = new() { "1", "2" };
            foreach (var id in myList)
            {
                using (var uow = unitOfWorkManager.Begin(isTransactional: true))
                {
                    var product = await productRepository.GetAsync(id);
                    product.SetName(name);
                    await productRepository.UpdateAsync(product);
                    await uow.CompleteAsync();
                }
            }
        }

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi This is because the UpdateAsync is already in a unit of work.

  • User Avatar
    0
    ademaygun created

    Hi, Even though await uow.CompleteAsync(); is being called, it is not performing any operation. In this case, I would expect it to write(commit) to the database or throw an error.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    CompleteAsync will do nothing if there is a parent unit of work.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09