I have a basic razor pages edit page with a form. I am using TryUpdateModelAsync to update the model and persisting it to a database.
var userToUpdate = await _context.Users.FindAsync(id);
if (await TryUpdateModelAsync<User>(
userToUpdate,
"user",
e => e.X, e => e.Y, e => e.Z ))
{
await _context.SaveChangesAsync();
return Page();
}
However, my user entity has over 50 fields. Instead of manually typing out all the user fields (and potentially making mistakes), is there a way where I can update all the fields except a few? :
TryUpdateModelAsync<User>(
userToUpdate,
"user",
e !=> e.SecretField
))
I am aware that I could make a user VM, but I don't want to have that duplication in my codebase.