Open Closed

bulk user creation #5935


User avatar
0
shobhit created
  • ABP Framework version: v4.2.2
  • UI Type: Angular
  • Database System: EF Core (SQL Server, Oracle, MySQL, PostgreSQL, etc..) SQL Server
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

How i can create Bulk user and user record should be commited in DB without waiting for transaction to complete.


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

    Hi,

    You can create users using a separate transaction. for example:

    foreach(var item in list)
    {
        using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional:true))
        {
            try
            {
                var user = new IdentityUser(
                    GuidGenerator.Create(),
                    <username>, /// item.Username
                    <email>, // item.email
                    CurrentTenant.Id
                );
        
                user.SetPhoneNumber(<phoneNumber>, false);
                
                await UserManager.CreateAsync(user, <password>)).CheckErrors();
        
                await uow.CompleteAsync();
            }
            catch (Exception e)
            {
                await uow.RollbackAsync();
                throw e;
            }
        }
    }
    
    
Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09