try { } catch (DbEntityValidationException dbex) { string errMsg = string.Empty; foreach (var eve in dbex.EntityValidationErrors) { errMsg += string.Format("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) { errMsg += string.Format("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } return new OperationResult(OperationResultType.Error, errMsg); } catch (Exception ex) { return new OperationResult(OperationResultType.Error, ex.ToString()); }
捕获EF提交异常
最新推荐文章于 2022-05-04 16:20:46 发布