相关疑难解决方法(0)

一个或多个实体的验证失败.有关详细信息,请参阅"EntityValidationErrors"属性.代码优先

我收到此错误:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Run Code Online (Sandbox Code Playgroud)

当我尝试使用Update-Database程序包管理器控制台中的命令更新数据库时.

如何在visual studio中将行写入输出窗口?

我试过了:

try
{
    context.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException e)
{
    foreach (var eve in e.EntityValidationErrors)
    {
        System.Diagnostics.Debug.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)
        {
            System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                ve.PropertyName, ve.ErrorMessage);
        }
    }
    throw;
}
Run Code Online (Sandbox Code Playgroud)

但那没用.关于如何调试这个的任何其他建议?

ef-code-first nuget-package entity-framework-5

8
推荐指数
1
解决办法
2万
查看次数