“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中找到,是因为增加的数据超出了最大长度限制!

上一篇:Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法【转载】


下一篇:Eclipse 启动报错 An internal error occurred during: "Initializing Java Tooling"