首页 > 其他 > 详细

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

时间:2016-09-27 14:53:17      阅读:274      评论:0      收藏:0      [点我收藏+]

http://stackoverflow.com/questions/7795300/validation-failed-for-one-or-more-entities-see-entityvalidationerrors-propert

捕获异常之后,判断是否为DbEntityValidationException

var e = exception as DbEntityValidationException;
            if (e != null)
            {
                foreach (var eve in e.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Value: \"{1}\", Error: \"{2}\"",
                            ve.PropertyName,
                            eve.Entry.CurrentValues.GetValue<object>(ve.PropertyName),
                            ve.ErrorMessage);
                    }
                }
            }

 

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

原文:http://www.cnblogs.com/chucklu/p/5912642.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!