Module Zero UserManager CreateAsync - Id of created entity not set on user object
See original GitHub issueThe following code is provided by Module Zero and is found in UserAppService.cs
public override async Task<UserDto> Create(CreateUserDto input)
{
CheckCreatePermission();
var user = ObjectMapper.Map<User>(input);
user.TenantId = AbpSession.TenantId;
user.Password = new PasswordHasher().HashPassword(input.Password);
user.IsEmailConfirmed = true;
//Assign roles
user.Roles = new Collection<UserRole>();
foreach (var roleName in input.RoleNames)
{
var role = await _roleManager.GetRoleByNameAsync(roleName);
user.Roles.Add(new UserRole(AbpSession.TenantId, user.Id, role.Id));
}
CheckErrors(await _userManager.CreateAsync(user));
return MapToEntityDto(user);
}
Should _userManager.CreateAsync(user) populate the user object Id after creation? If I check the value of user.Id after CreateAsync, the value is still zero 0.
CheckErrors(await _userManager.CreateAsync(user));
var x = user.Id; /// This is equal to zero 0
My understanding was that CreateAsync would update the user object to include the Id value of the inserted entity. Is this a bug? Does this have something to do with Async?
Thanks.
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
UserManager.CreateAsync does not generate Id
I just upgraded my MVC 5 application (was previously MVC 3 with SimpleMembership ) to ASP.NET Identity 2.0 and I can work with...
Read more >Module Zero UserManager CreateAsync - Id of created ...
The following code is provided by Module Zero and is found in UserAppService.cs public override async Task<UserDto> Create(CreateUserDto ...
Read more >Custom User Management in ASP.NET Core MVC ...
We will start off by creating a new ASP.NET Core 3.1 MVC Project with Authentication Mode selected as Individual User Accounts.
Read more >Articles Tutorials | AspNet Boilerplate
User Login Module Zero defines LoginManager which has a LoginAsync method used for logging into the application. It checks all logic for the...
Read more >Issue when check identity FindByNameAsync on debug it ...
Try changing this line to: var Identityuser = userManager.FindByNameAsync(request.UserName).Result;. Please sign in to rate this answer.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
My bad. I see that
MapToEntityDto(user)
is called before ABP has a chance to save changes.Thanks for the help.
Yes, I did check on the client side. Using the attribute, [UnitOfWork], I still get an id value of zero 0 on the client side.
If I add the line UnitOfWorkManager.Current.SaveChanges(); to the original Create method as detailed above, then an Id value is returned on the client side.
Thanks.