public static DbEntityValidationResult RemoveEFFalseAlarms(this DbContext context, DbEntityValidationResult result, DbEntityEntry entityEntry) { IDirectUpdateContext directContext = context as IDirectUpdateContext; if (directContext != null) { DirectUpdateMode?mode = directContext.CurrentSaveOperationMode; if (mode.HasValue && mode.Value == DirectUpdateMode.AllowAll) { List <DbValidationError> errorsToIgnore = new List <DbValidationError>(); foreach (DbValidationError error in result.ValidationErrors) { if (entityEntry.State == EntityState.Modified) { DbMemberEntry member = entityEntry.Member(error.PropertyName); DbPropertyEntry property = member as DbPropertyEntry; if (property != null) { if (!property.IsModified) { errorsToIgnore.Add(error); } } } } errorsToIgnore.ForEach(e => result.ValidationErrors.Remove(e)); } } return(result); }
public static DbEntityValidationResult RemoveEFFalseAlarms(this DbContext context, DbEntityValidationResult result, DbEntityEntry entityEntry) { //This function doesn't do anything unless AllowAll is the mode IDirectUpdateContext directContext = context as IDirectUpdateContext; if (directContext != null) { UpdateMode?mode = directContext.CurrentSaveOperationMode; if (mode.HasValue && mode.Value == UpdateMode.Allow) { List <DbValidationError> errorsToIgnore = new List <DbValidationError>(); foreach (DbValidationError error in result.ValidationErrors) { if (entityEntry.State == EntityState.Modified) { DbMemberEntry member = entityEntry.Member(error.PropertyName); DbPropertyEntry property = member as DbPropertyEntry; if (property != null) { if (!property.IsModified) { //Add errors that resulted from not changing all the attributes errorsToIgnore.Add(error); } } } } //Then the errors are ignored errorsToIgnore.ForEach(e => result.ValidationErrors.Remove(e)); } } return(result); }