Validation failed for one or more entities while saving changes to SQL Server Database using Entity

Total Post:52

Points:366
C#
 799  View(s)
Ratings:
Rate this:

 I am getting this error while using entityframework mvc 4 . I want to save data into database but getting this error\

Validation failed for one or more entities while saving changes to SQL Server Database using Entity 

  1. Post:45

    Points:323
    Re: Validation failed for one or more entities while saving changes to SQL Server Database using Entity

    You can extract all the information from the DbEntityValidationException with the following code (you need to add the namespaces: System.Data.Entity.Validation and System.Diagnostics to your using list):

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

      Modified On Apr-11-2018 11:28:15 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!