Reputation: 515
When updating a row from a detached entity, I'm trying to avoid updating fields which haven't changed, using this:
DbEntityEntry<Type> entry = context.Entry(entity);
entry.Property(p => p.Property).IsModified = false;
This works fine for nullable fields, but when it's a non nullable field EF throws a validation exception saying that the field is required.
Anyone have any insight into why this doesn't work and if I must fiddle around with original values to overcome it?
I'm using EF 5.0 and the DBContext-API.
Upvotes: 1
Views: 254
Reputation: 364269
The reason is validation logic inside EF. The validation is always triggered on the whole entity - it doesn't respect modifications. The solution is to disable entity validation logic in EF:
context.Configuration.ValidateOnSaveEnabled = false;
Upvotes: 2