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());
            }

相关文章:

  • 2022-12-23
  • 2021-04-22
  • 2021-05-13
  • 2021-08-13
  • 2021-09-04
  • 2021-10-22
  • 2021-07-26
猜你喜欢
  • 2021-07-07
  • 2021-05-02
  • 2022-02-14
  • 2021-12-06
相关资源
相似解决方案