Ends in:
3 DAYS
11 HRS
31 MIN
58 SEC
Ends in:
3 D
11 H
31 M
58 S
Open Closed

autoSave = true does not work as expected #2537


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

Hi, I am trying to understand the purpose of autoSave parameter in repository methods:

        // Parameters:
        //   autoSave:
        //     Set true to automatically save changes to database. This is useful for ORMs /
        //     database APIs those only save changes with an explicit method call, but you need
        //     to immediately save changes to the database.

from the coding comment above, I expect every time I set the autoSave = true, the record will be inserted immediately into database without waiting for the scope of method to be completed (UOW), but it does not work as expected, the item is not inserted into database whether I set it to true or false.

I can solve the problem by calling _unitOfWorkManager.Current.SaveChangesAsync(), but anyone can explain what the autoSave prameter trying to do?


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

    hi

    Can you share your code to reproduce?

    autoSave mean dbContext.SaveChangesAsync

  • User Avatar
    0
    nhontran created

    Hi @maliming,

    Sorry for my late reply, I have shared the code to your email, please help us take a look.

    var product = ObjectMapper.Map<ProductCreateDto, Product>(input);
    
    // create product 1
    product = await _productRepository.InsertAsync(product, autoSave: true);
    
    // issue: product 1 was not created when I was debugging to this return line of code
    return ObjectMapper.Map<Product, ProductDto>(product);
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    At this point the unit of work has not been completed and the transaction has not been committed. https://docs.abp.io/en/abp/latest/Unit-Of-Work

Made with ❤️ on ABP v9.1.0-preview. Updated on December 02, 2024, 12:35