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

posted @ 2018-01-17 23:28  雲霏霏  阅读(13431)  评论(0编辑  收藏  举报