System.Data.Entity.Validation.DbEntityValidationException, See 'EntityValidationErrors' property for more details.
目录
System.Data.Entity.Validation.DbEntityValidationException:“Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.”
解决方案
使用 try catch 捕获 DbEntityValidationException 异常。
C# 全选
try
{
//省略代码
}
catch (DbEntityValidationException ex)
{
//System.Data.Entity.Validation.DbEntityValidationException:
//“Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.”
//获取校验错误信息
StringBuilder sb = new StringBuilder();
foreach (DbEntityValidationResult err in ex.EntityValidationErrors)
{
sb.AppendLine("实体:" + err.Entry.Entity.GetType().FullName);
foreach (var x in err.ValidationErrors)
{
sb.AppendLine(x.ErrorMessage);
}
}
throw new Exception(sb.ToString());
}
catch (Exception ex)
{
throw;
}
前端界面显示异常信息:
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网