Validation failed for one or more entities. See 'EntityValidationErrors' property for more d
Posted Rocken.li
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Validation failed for one or more entities. See 'EntityValidationErrors' property for more d相关的知识,希望对你有一定的参考价值。
详细信息中没显示是哪个字段验证出错:
Validation failed for one or more entities解决方法
{
Context.SaveChanges();
}
catch (DbEntityValidationException ex)
{
StringBuilder errors = new StringBuilder();
IEnumerable<DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
foreach (DbEntityValidationResult result in validationResult)
{
ICollection<DbValidationError> validationError = result.ValidationErrors;
foreach (DbValidationError err in validationError)
{
errors.Append(err.PropertyName + ":" + err.ErrorMessage + "\r\n");
}
}
Console.WriteLine(errors.ToString());
//简写
//var validerr = ex.EntityValidationErrors.First().ValidationErrors.First();
//Console.WriteLine(validerr.PropertyName + ":" + validerr.ErrorMessage);
}
结果显示:
以上是关于Validation failed for one or more entities. See 'EntityValidationErrors' property for more d的主要内容,如果未能解决你的问题,请参考以下文章
Validation failed for one or more entities. See 'EntityValidationErrors' property for more d
Validation failed for one or more entities. See ‘EntityValidationErrors
“Validation failed for one or more entities”异常的解决办法
Validation failed for argument [0]
报错Validation failed for object='userLogin'. Error count: 1
spring boot 表单的实体提交错误:Validation failed for object='book'. Error count: 2