I understand that updating objects without first selecting them is a common problem, and many solutions are already in StackOverflow, however after reading these problems I still have a problem.
I use the following code to update User entitiy:
using (var context = GetContext()) { var userEntity = new UserEntity() { ID = userUpdate.ID }; context.Users.Attach(userEntity); context.Entry(userEntity).CurrentValues.SetValues(userUpdate); context.SaveChanges(); }
However, this leads to the fact that a DbEntityValidationException thrown due to the fact that my User entitiy has some required properties, but they are not necessarily set in the updated object.
Is there a way around this or is it just a case of removing the required properties?
Thanks!
source share