catch (DbEntityValidationException ex) { StringBuilder errors = new StringBuilder(); IEnumerable<DbEntityValidationResult> validationResult = ex.EntityValidationErrors; foreach (DbEntityValidationResult sr in validationResult) { ICollection<DbValidationError> validationError = sr.ValidationErrors; foreach (DbValidationError err in validationError) { errors.Append(err.PropertyName + ":" + err.ErrorMessage + " "); } } }
EntityFramework保存数据库是因字段限制抛出异常如何捕获