Starts in:
1 DAY
23 HRS
21 MIN
20 SEC
Starts in:
1 D
23 H
21 M
20 S
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 November 20, 2024, 13:06