Entity Framework Error | not handled in user code

Asked

Viewed 112 times

1

Hello, I need help in the following scenario.

I have a class, where the field is Int64 in the backend and in SQL Server the field is bigint.

ObjClasse.VariavelInteira = numInt;
db.SaveChanges();

When saving, the error you present is:

An Exception of type 'System.Data.Entity.Validation.Dbentityvalidationexception' occurred in Entityframework.dll but was not handled in user code

How can I identify the error?

  • Classe is an object? Or a class accessing a static member?

  • 1

    I edited the question to correct. I took the opportunity to edit corresponding to your answer. Because it was crucial for me to identify (and solve) the problem. Thank you.

  • Show! I knew this would be easy to solve.

1 answer

5


This is a generic error saying that some validation failed. To capture the specific error, you can do the following

try
{
    Classe.VariavelInteira = numInt;
    db.SaveChanges();
}
catch (DbEntityValidationException ex)
{    
    var errorMessages = ex.EntityValidationErrors
            .SelectMany(x => x.ValidationErrors)
            .Select(x => x.ErrorMessage);

    var fullErrorMessage = string.Join("; ", errorMessages);         
    var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

    //Use a variável exceptionMessage para ver os erros de validação
}

If after that, you still need help, edit your question with the errors returned.

  • http://stackoverflow.com/questions/7795300/validation-failed-for-one-or-more-entities-see-entityvalidationerrors-propert

  • I don’t understand. I’m sorry.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.