Se usate Entity Framework e se, come me, allineate le piccole modifiche sul “dominio” con modifiche manuali sul DB (specialmente quando avete anni di dati dentro
), vi può capitare di ottenere il seguente errore:
Validation failed for one or more entities. See 'EntityValidationErrors' property for more details
A volte scoprire dov’è il problema di validazione non è così facile e può venire utile metterci un try-catch di questo tipo:
try
{
ctx.SaveChanges();
}
catch (DbEntityValidationException e)
{
foreach (var eve in e.EntityValidationErrors)
{
Debug.Print("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)
{
Debug.Print("- Property: \"{0}\", Error: \"{1}\"",
ve.PropertyName, ve.ErrorMessage);
}
}
throw;
}
Ovviamente grazie a Stackoverflow per la dritta 
Certo, se usaste CQRS e I database documentali non avreste di questi problemi, ma questa è un’altra storia 
posted @ giovedì 24 ottobre 2013 18:36