Verification failed for one or more objects

I have the following code in an asp.net MVC3 application:

string msg = "Beginning report run for: ";
            msg += " Obligor Registry ID: " + obligorID;
            msg += " Requesting Organization Registry ID:" + requestingOrgID;
            msg += " Requesting Agent Registry ID: " + requestingAgentID;

            TransactionLog lg = new TransactionLog();
            lg.TransactionTypeId = 2;
            lg.Message = msg;    


             context.TransactionLogs.Add(lg);
             long referenceNumber = context.SaveChanges();
            return referenceNumber;

and I get the following error:

Validation failed for one or more entities. See 'EntityValidationErrors' property for more details. 
+3
source share
3 answers

While you are in debug mode in the block catch {...}, open the QuickWatch window ( ctrl+ alt+ q) and paste in:

((System.Data.Entity.Validation.DbEntityValidationException)ex).EntityValidationErrors

This will allow you to turn into a tree ValidationErrors. This is the easiest way to find an instant understanding of these errors.

+16
source
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);
        }
    }
}

You need a namespace: System.Data.Entity.Validation

+2
source

@GONeale helped me in this regard. Also, the reason for this exception in my case is because I have certain non-zero db fields that I did not include in the partial update of the response for a specific transaction. context.Database.ExecuteSQLCommand will be my suggestion in this case.

+1
source

All Articles