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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM