“Validation failed for one or more entities”异常的解决办法

日志中出现Entity Framework修改数据库时的错误:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

从表面看不出来哪里错了,增加以下try...catch代码,捕获异常:

try
{
// 数据库操作
}

catch (DbEntityValidationException ex)
{

}

最终在ex.EntityValidationErrors中找到,是因为增加的数据超出了最大长度限制!

原文地址:https://www.cnblogs.com/yunfeifei/p/8306813.html