Open Closed

DbConcurrency errors when overriding IdentityUserManager Create method. #274


User avatar
0
talhazengin created
  • ABP Framework version: v2.9.0
  • UI type: Angular
  • Identity Server Seperated (Angular): yes
  • Exception message and stack trace: AbpIdentityResultException, AbpDbConcurrencyException, DbUpdateConcurrencyException
  • Steps to reproduce the issue:
Hello,
I am trying to customize IdentityUserManager without success.
I wanted to update my custom User Entity properties after User created.
But that code gives DbConcurrency Errors.
I wanted to handle(EfCore https://docs.microsoft.com/en-us/ef/core/saving/concurrency) the exception but could not catch any exception.
Any advice is helpful, thanks.


13 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi, ABP uses the unit of work system to save changes after the method returns, but you can save changes manually:

    Try :

      try
      {
        //......
        await _myRepository.UpdateAsync(myEntity);
        await CurrentUnitOfWork.SaveChangesAsync();
      }
      catch(DbUpdateConcurrencyException  ex)
      {
         // handle exception
      }
    

    See Unit of Work Document learn more about unit of work system.

  • User Avatar
    0
    talhazengin created

    Nope optimistic concurrency failure again. I tried many usage combination of UOW. Transactional UOW etc. Maybe i need an example project.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Can you provide steps to reproduce? I will try reproduce your problem locally , Thanks.

  • User Avatar
    0
    talhazengin created

    Hi @liangshiwei,

    I sent you a mail. I did a small demo application. Did you get the email?

    Thanks.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    OK, I will check it.

    Have a ncie day.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I create an example for you https://github.com/realLiangshiwei/AbpQa274.

    You can see that after create the user, change the user object again.

    You have three options:

    1. Overwrite IdentityUserAppService, update the user at the end of the method.
    2. Use entity extend system.(this way is used in the example).
    3. Can be simpler,Use object extend system to extend Dto and pass the DisplayName parameter in the create user request. see https://github.com/abpframework/abp/issues/4467.
  • User Avatar
    0
    talhazengin created

    Hi,

    First of all i thank you, but Option 2 saves property as ExtraProperty which is not we want because our property is a real DB field. I assume Option 3 is the same. I will try Option 1, i will write the result.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    It is a separate field in database table: https://docs.abp.io/en/abp/latest/Customizing-Application-Modules-Extending-Entities#entity-extensions-ef-core

    You can run the sample project and add users. You will see it is a separate field in the database.

  • User Avatar
    0
    talhazengin created

    I had to use

    builder.Ignore<MyUser>();
    

    This code when dbmigration model creating but in your demo application you didn't use this option. If i don't use this, it shows "I can't map ExtraProperties" error when trying to add a new migration.

  • User Avatar
    0
    talhazengin created

    Is this AppUser name necessary ? Because we removed it and we added a new entity like MyUser.

  • User Avatar
    0
    talhazengin created

    I fixed this but i used this code in MigrationDbContext.OnModelCreating

    builder.Ignore<MyUser>();
    

    Fyi.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    AppUser is no different from your MyUser, you can start directly from AppUser.

    We changed the startup template and removed the ConfigureCustomUserProperties method in later versions. You can change your code according to the latest template.

    Because you fixed this. so I close this question. if you still have this problem, please reopen.

  • User Avatar
    0
    talhazengin created

    No problem but only strange thing is this code. Because you didn't use this, but i had to use this. I got an existing db, maybe the problem cause of this.

    builder.Ignore<MyUser>();
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 26, 2024, 06:07