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

Validation failed for one or more entities.

时间:2015-05-20 14:37:24      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:

 验证失败后用DbEntityValidationException 查找出错的字段

try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges int effect = await _unitOfWorkAsync.SaveChangesAsync(); } catch (System.Data.Entity.Validation.DbEntityValidationException e) { 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}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; }

 

Validation failed for one or more entities.

标签:

原文地址:http://www.cnblogs.com/xiaoyu369/p/4517050.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!