-1

Hi, am trying save the Client Note but it's showing this error, please can someone help me to resolve this. Am using a notes page in my application, it will save until certain words. If am crossing that and trying to save, it's showing the error as"Validation failed for one or more entities. See 'EntityValidationErrors' property for more details."

Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160
Sriki
  • 13
  • 1
  • 4
  • Hi, can you show us the code? – Tomas Pastircak Apr 09 '14 at 17:45
  • If you use **Entity Framework** you can have a look at my answer on [Solution for “Validation failed for one or more entities. See 'EntityValidationErrors' property for more details](http://stackoverflow.com/questions/21486072/solution-for-validation-failed-for-one-or-more-entities-see-entityvalidatione/29031857#29031857). Hope this helps... – Murat Yıldız Jan 26 '16 at 23:14

1 Answers1

0

Use this chunk of code, this will tell you exactly on what column of which entity validation is failing, and you will eaisly reach the place where its creating problem.

 try
 {
     db.SaveChanges();
 }
 catch (DbEntityValidationException ex)
 {
     // Retrieve the error messages as a list of strings.
     var errorMessages = ex.EntityValidationErrors
                           .SelectMany(x => x.ValidationErrors)
                           .Select(x => x.ErrorMessage);

     // Join the list to a single string.
     var fullErrorMessage = string.Join("; ", errorMessages);

     // Combine the original exception message with the new one.
     var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);

    // Throw a new DbEntityValidationException with the improved exception message.
   throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors);
 }
Ehsan Sajjad
  • 61,834
  • 16
  • 105
  • 160