TryUpdateModel
doesn't actually do anything to the item passed into it. It merely runs model validation on it. Whatever values were there, remain there.
I think I know what the issue is, and it's related to AutoMapper. Your posted model most likely doesn't include the actual related user object, just the id you posted for that. When you map your model onto your entity, AutoMapper is replacing the value for the related user object with null
, since the model doesn't have it. Try adding the following to your CreateMap
:
.ForMember(dest => dest.User, opts => opts.Ignore());