Tag Archives: Iori’s toolbox

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

If Code First is used, after miragtion is completed using Update Database-verbose, the run finds an exception:

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

This is due to migration changes to the model that result in restrictions on columns in the DB (for example, StringLength(30) causes NVARCHar (Max) to become NVarchar (30))

Want to see the details of the exception, can catch DbEntityValidationException:

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)
    {
    }
}