`
mybwu_com
  • 浏览: 178394 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

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

 
阅读更多

如果使用的是Code First,使用update database -verbose完成了miragtion 之后,运行发现异常:


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


这是由于migration对model的更改导致了db中column的限制(例如长度,StringLength(30)会导致nvarchar(max)变为nvarchar(30))


想要看到异常的具体信息,可以catchDbEntityValidationException :


try
{
    // Your code...
    // Could also be before try if you know the exception occurs in SaveChanges

    context.SaveChanges();
}
catch (DbEntityValidationException e)
{
    foreach (var eve in e.EntityValidationErrors)
    {
    }
}


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics