码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-09-27 14:54:33      阅读:311      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!