Entity Framework: Debugging Error from DbEntityValidationResult and DbentityValidationException

Standard

Use below code to find exact issue for validation exception by Entity Framework:

catch (DbEntityValidationException Ex)
{
    foreach (var Errors in Ex.EntityValidationErrors)
    {
        foreach (var valError in Errors.ValidationErrors)
        {
            Trace.TraceInformation("Property: {0} Error: {1}", valError.PropertyName, valError.ErrorMessage);
        }
    }
}

 

Or Just place below code in watch window as soon you hit by exception during debugging

((System.Data.Entity.Validation.DbEntityValidationException)$exception).EntityValidationErrors.First().ValidationErrors.First().ErrorMessage

 

2016-02-16 16_42_02-MyHomepage (Debugging) - Microsoft Visual Studio

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s