一个或多个实体的验证失败。有关更多详细信息,请参阅entityvalidationerrors属性。 [英] Validation failed for one or more entities. See entityvalidationerrors property for more details.

查看:119
本文介绍了一个或多个实体的验证失败。有关更多详细信息,请参阅entityvalidationerrors属性。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个或多个实体的验证失败。有关详细信息,请参阅entityvalidationerrors属性。



删除了SHOUTING - OriginalGriff [/ edit]

Validation failed for one or more entities. See entityvalidationerrors property for more details.

[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

使用异常处理程序获取详细的错误信息,如下所示。



Use exception handler to get detailed error info as given below.

try
{
    // Your code...
    // Could also be before try if you know the exception occurs in SaveChanges

    context.SaveChanges();
}
catch (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;
}


这篇关于一个或多个实体的验证失败。有关更多详细信息,请参阅entityvalidationerrors属性。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆