title: Update method - Value cannot be null. (Parameter 'entity') error 500
body: <p>I test my app by postman:</p>
  <p>statuscode:500</p>
  <p>messsage: Value cannot be null. (Parameter 'entity')</p>
  <p>details: at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)\r\n   at Microsoft.EntityFrameworkCore.DbContext.Entry[TEntity](TEntity entity)\r\n   at API.Data.UserRepository.Update(AppUser user) in C:\Users\vu227\DatingApp\API\Data\UserRepository.cs:line 67\r\n   at API.Controllers.UsersController.UpdateUser(MemberUpdateDto memberUpdateDto) in C:\Users\vu227\DatingApp\API\Controllers\UsersController.cs:line 51\r\n   at lambda_method101(Closure , Object )\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State&amp; next, Scope&amp; scope, Object&amp; state, Boolean&amp; isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()\r\n--- End of stack trace from previous location ---\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Logged|17_1(ResourceInvoker invoker)\r\n   at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)\r\n   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)\r\n   at API.Middleware.ExceptionMiddleware.InvokeAsync(HttpContext context) in C:\Users\vu227\DatingApp\API\Middleware\ExceptionMiddleware.cs:line 29&quot;</p>
  <p>AppUser</p>
  <pre><code> using System;
   using System.Collections.Generic;
   using API.Extensions;
  
   namespace API.Entities
    {
     public class AppUser
      {
      public int Id { get; set; }
      public string UserName { get; set; }
      public  byte[] PasswordHash { get; set; }
      public byte[] PasswordSalt { get; set; }
      public DateTime DateOfBirth { get; set; }
      public string KnownAs { get; set; }
      public DateTime Created { get; set; } = DateTime.Now;
      public DateTime LastActive { get; set; } = DateTime.Now;
      public string  Gender { get; set; }
      public string Introduction { get; set; }
      public string LookingFor { get; set; }
      public string Interests { get; set; }
      public string City { get; set; }
      public string  Country  { get; set; }
      public ICollection&lt;Photo&gt; Photos { get; set; }
  }
  </code></pre>
  <p>}</p>
  <pre><code>public void Update(AppUser user)
      {
          _context.Entry(user).State = EntityState.Modified;
      }
  </code></pre>
  <p>line 67 in UserRepostory is</p>
  <pre><code>_context.Entry(user).State = EntityState.Modified;
  </code></pre>
  <p>Controller Put method looks like:</p>
  <pre><code>   [HttpPut]
      public async Task&lt;ActionResult&gt; UpdateUser(MemberUpdateDto memberUpdateDto)
      {
          var claimsIdentity = User.Identity as System.Security.Claims.ClaimsIdentity;
          var username = claimsIdentity.Name;
          var user = await _userRepository.GetUserByUsernameAsync(username);
  
          _mapper.Map(memberUpdateDto, user);
  
          _userRepository.Update(user);
  
          if (await _userRepository.SaveAllAsync()) return NoContent();
  
          return BadRequest(&quot;Failed to update user&quot;);
      }
  </code></pre>
  <p>Line 51 is</p>
  <p>_userRepository.Update(user);</p>
  <p>MemberUpdateDto:</p>
  <pre><code> namespace API.DTOs
    {
     public class MemberUpdateDto
      {
      public string Introduction { get; set; }
      public string LookingFor { get; set; }
      public string Interests { get; set; }
      public string City { get; set; }
      public string Country { get; set; }
      
       }
    }
  </code></pre>
  <p>Mapper:</p>
  <pre><code> public class AutoMapperProfiles : Profile
  {
      public AutoMapperProfiles()
      {
          CreateMap&lt;AppUser, MemberDto&gt;()
          .ForMember(dest =&gt; dest.PhotoUrl, opt =&gt; opt.MapFrom(src =&gt; 
                  src.Photos.FirstOrDefault(x =&gt; x.IsMain).Url))
              .ForMember(dest =&gt; dest.Age, opt =&gt; opt.MapFrom(src =&gt; src.DateOfBirth.CalculateAge()));;
          CreateMap&lt;Photo, PhotoDto&gt;();
          CreateMap&lt;MemberUpdateDto, AppUser&gt;();
      }
  }
  </code></pre>