In our database we have a user. A user can have certain metadata (Like their location, age, etc) associated with them. In addition to that they have a profile image.
A user can edit any of these things at any time.

The problem we run into is that when a user goes to edit their information, but they don’t choose an image — the previous image gets erased (Null).
I figure that when we go to save the modified user, we should be able to say if(user.profileImage == null) don't save it
I figure that would come into play in our user repository which uses the following code:
public void SaveUser(Domain.Entities.User user)
{
if (user.UserId == 0)
{
context.Users.Add(user);
}
else
{
context.Entry(user).State = EntityState.Modified;
//The logic would be here
}
context.SaveChanges();
}
However I seems that no matter what we try it doesn’t work.
So my question is: Is there a way to check changes to individual fields instead of the entire EntityState?
I ended up storing image data in the Session and then if the image upload was null I simply inserted the session attribute into my image, effectively keeping the old image if left empty.
Session["image"] = productService.GetProduct(id).Image;Then in the post I said…