Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法

Validation failed for one or more entities. See ‘EntityValidationErrors’解决方法

 

You can extract all the information from the DbEntityValidationException with the following code (you need to add the namespaces: System.Data.Entity.Validation and System.Diagnostics to your using list):

catch (DbEntityValidationException dbEx)
{
    foreach (var validationErrors in dbEx.EntityValidationErrors)
    {
        foreach (var validationError in validationErrors.ValidationErrors)
        {
            Trace.TraceInformation("Property: {0} Error: {1}", 
                                    validationError.PropertyName, 
                                    validationError.ErrorMessage);
        }
    }
}
posted @ 2016-12-15 10:51  需要GIS小工具找我  阅读(362)  评论(0编辑  收藏  举报