Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Update user record after create #4121


User avatar
0
[email protected] created

I might not be understanding how the database UOW and async calls work as when I do the following - I get an error that the user record 'n' does not exist. What is the correct way to update the user record inside the one call from the Browser.

thanks

        CheckErrors(await _userManager.CreateAsync(user));
       await CurrentUnitOfWork.SaveChangesAsync();
        user.UserName = $"{DateTime.Now.Year}_{userName}_{user.Id}";

        await _userManager.UpdateAsync(user);
        await CurrentUnitOfWork.SaveChangesAsync();

4 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team
    • Can you post the actual error?
    • Try commenting out this line: await _userManager.UpdateAsync(user);
  • User Avatar
    0
    [email protected] created

    An unhandled exception occurred while processing the request. EntityNotFoundException: There is no such an entity. Entity type: Furiosotoro.Furiosotoro.Authorization.Users.User, id: 20

    Abp.Domain.Repositories.AbpRepositoryBase+<GetAsync>d__21.MoveNext() in AbpRepositoryBase.cs, line 86

    Stack Query Cookies Headers 
    
    EntityNotFoundException: There is no such an entity. Entity type: Furiosotoro.Furiosotoro.Authorization.Users.User, id: 20
        Abp.Domain.Repositories.AbpRepositoryBase+&lt;GetAsync&gt;d__21.MoveNext() in AbpRepositoryBase.cs
        System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        Abp.Threading.InternalAsyncHelper+&lt;AwaitTaskWithPostActionAndFinallyAndGetResult&gt;d__5.MoveNext() in InternalAsyncHelper.cs
        System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        Abp.Authorization.Users.AbpUserStore+&lt;GetUserNameFromDatabaseAsync&gt;d__88.MoveNext()
        System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        Abp.Authorization.Users.AbpUserManager+&lt;UpdateAsync&gt;d__41.MoveNext() in AbpUserManager.cs
        System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
        System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
        System.Runtime.CompilerServices.TaskAwaiter.GetResult()
        Furiosotoro.Furiosotoro.Authorization.Users.UserRegistrationManager+&lt;RegisterAsync&gt;d__13.MoveNext() in UserRegistrationManager.cs
    
                await _userManager.UpdateAsync(user);
    

    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) System.Runtime.CompilerServices.TaskAwaiter.GetResult() Furiosotoro.Furiosotoro.Web.Controllers.AccountController+<Register>d__38.MoveNext() in AccountController.cs

                    var user = await _userRegistrationManager.RegisterAsync(
    

    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) lambda_method(Closure , object ) Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeActionMethodAsync>d__12.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeNextActionFilterAsync>d__10.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker+<InvokeInnerFilterAsync>d__14.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextExceptionFilterAsync>d__23.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ExceptionContext context) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeNextResourceFilter>d__22.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeFilterPipelineAsync>d__17.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker+<InvokeAsync>d__15.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Builder.RouterMiddleware+<Invoke>d__4.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware+<Invoke>d__4.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) IdentityServer4.Hosting.IdentityServerMiddleware+<Invoke>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+<Invoke>d__6.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware+<Invoke>d__7.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) IdentityServer4.Hosting.BaseUrlMiddleware+<Invoke>d__3.MoveNext() System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Furiosotoro.Furiosotoro.Web.Authentication.JwtBearer.JwtTokenMiddleware+<>c__DisplayClass0_0+<<UseJwtTokenMiddleware>b__0>d.MoveNext() in JwtTokenMiddleware.cs

                    await next();
    

    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) Furiosotoro.Furiosotoro.Web.Authentication.JwtBearer.JwtTokenMiddleware+<>c__DisplayClass0_0+<<UseJwtTokenMiddleware>b__0>d.MoveNext() in JwtTokenMiddleware.cs

                        await next();
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    Microsoft.AspNetCore.Authentication.AuthenticationMiddleware+&lt;Invoke&gt;d__6.MoveNext()
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware+&lt;Invoke&gt;d__7.MoveNext()
    
  • User Avatar
    0
    aaron created
    Support Team

    Did you try this?

    1. Try commenting out this line: await _userManager.UpdateAsync(user);
  • User Avatar
    0
    ismcagdas created
    Support Team

    @[email protected],

    If @aaron's suggestion does not work, can you share your full method ? Is it in an application service ?

    Thanks.