现在的位置: 首页 > 综合 > 正文

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

2013年05月05日 ⁄ 综合 ⁄ 共 588字 ⁄ 字号 评论关闭
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;
}
【上篇】
【下篇】

抱歉!评论已关闭.