Monday, 8 December 2014

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. Entity FrameWork

I got an Error in Entity framework while insertion of Records.

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.























This kind of Issue's will come in various causes, We can  watch the Entity frame work Errors in visual studio with the Following Code.

   

    catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                Exception ErrorRaise = ex;
                foreach (var validationErrors in ex.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        string errorMessage = string.Format("{0}:{1}",
                            validationErrors.Entry.Entity.ToString(),
                            validationError.ErrorMessage);

                        ErrorRaise = new InvalidOperationException(errorMessage, ErrorRaise);
                    }
                }
                throw ErrorRaise;
            }



No comments:

Post a Comment