博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

查看Visual Studio异常内容

Posted on 2015-12-25 09:45  Jason.Liao  阅读(405)  评论(0编辑  收藏  举报

If Entity Framework throws a validation exception when saving, Visual Studio reports the message,

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

But the in-built ‘View Detail’ dialog doesn’t let you drill into the EntityValidationErrors property.

To view the EntityValidationErrors collection, add the following Watch expression to the Watch window.

((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors

Which displays a similar to,

 

The watch expression ‘$exception’ displays any exception thrown in the current context, even if it has not been caught and assigned to a variable.