zoukankan      html  css  js  c++  java
  • Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.

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




    详细信息中没显示是哪个字段验证出错:



    Validation failed for one or more entities解决方法

    try
    {
        Context.SaveChanges();
    }
    catch (DbEntityValidationException ex)
    {
        StringBuilder errors = new StringBuilder();
        IEnumerable<DbEntityValidationResult> validationResult = ex.EntityValidationErrors;
        foreach (DbEntityValidationResult result in validationResult)
        {
            ICollection<DbValidationError> validationError = result.ValidationErrors;
            foreach (DbValidationError err in validationError)
            {
                errors.Append(err.PropertyName + ":" + err.ErrorMessage + " ");
            }
        }
        Console.WriteLine(errors.ToString());
        //简写
        //var validerr = ex.EntityValidationErrors.First().ValidationErrors.First();
        //Console.WriteLine(validerr.PropertyName + ":" + validerr.ErrorMessage);
    }


    结果显示:

    引用内容
    Imsi:The field Imsi must be a string or array type with a maximum length of '20'
  • 相关阅读:
    MySQL 存储过程
    linux iptables 相关设置
    Ubuntu iptables 设置
    Mac OS 10.12
    解决:cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
    go get golang.org/x/net 安装失败的解决方法!
    Ubuntu16.04
    Ubuntu16.04
    Ubuntu16.04
    在Ubuntu16.04里面安装Gogland!
  • 原文地址:https://www.cnblogs.com/xdot/p/5254041.html
Copyright © 2011-2022 走看看