I'm trying to update 4 fields on my userprofile table, but i get the following error
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
My UserProfile class is constructed with many [Required] fields but I only display four which are
- First name
- Surname
- Email Address
- Website
Now my code currently looks like this
public void UpdateUserProfile(UserProfile userProfile)
{
using (var context = new Context())
{
context.UserProfile.Attach(userProfile);
var entry = context.Entry(userProfile);
entry.Property(e => e.Firstname).IsModified = true;
entry.Property(e => e.Surname).IsModified = true;
entry.Property(e => e.EmailAddress).IsModified = true;
entry.Property(e => e.UserWebsite).IsModified = true;
context.SaveChanges();
}
}
I've googled the error and from what I have read it seems I need to load everything thats linked to the UserId and then make the modifications? but to me that seems to much over head just to update four fields?