打开 关闭

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


User avatar
0
ademaygun 创建
  • 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 答案
  • User Avatar
    0
    maliming 创建
    支持团队 Fullstack Developer

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

  • User Avatar
    0
    ademaygun 创建

    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 创建
    支持团队 Fullstack Developer

    hi

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

Made with ❤️ on ABP v8.2.0-preview Updated on 三月 25, 2024, 15:11