I have just started a new project and having had previous happy times with Entity Framework, I Nuget’ed in the latest version. All was going well until I tried to update an entity. I have the following code;
In EF4, my understanding is that this would send an update statement to the database and only the FailedPasswordAttemptCount would be incremented for the user with the corresponding UserId.
In EF5, this craps out with a DbEntityValidationException as I have a non-nullable field in the user table (UserName).
I could solve this by creating my Data.User object with an empty UserName,
but this doesn’t seem particularly manageable as more non-nullable fields are added to this and numerous other tables.
It turns out there is now a property in EF called ValidateOnSaveEnabled ValidateOnSaveEnabled is a boolean which determines if entities should be validated automatically when SaveChanges() is invoked. It is set to true by default. Setting this to false got the code working again!