验证失败后用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; }

 

相关文章:

  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-24
  • 2021-08-05
  • 2021-10-13
  • 2022-02-10
相关资源
相似解决方案