I have the following Action method inside my Asp.net mvc web application:-
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(SDJoin sdj, FormC
You haven't shown the Save()
method but if you can add code like this to it you'll get an exception that contains all the details you're looking for
try
{
_context.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
{
Exception raise = dbEx;
foreach (var validationErrors in dbEx.EntityValidationErrors)
{
foreach (var validationError in validationErrors.ValidationErrors)
{
string message = string.Format("{0}:{1}",
validationErrors.Entry.Entity.ToString(),
validationError.ErrorMessage);
// raise a new exception nesting
// the current instance as InnerException
raise = new InvalidOperationException(message, raise);
}
}
throw raise;
}
Although this is an old post but this approach can be more fruitful!
Credits
Try something like this
try
{
pcontext.SaveChanges();
}
catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException ex)
{
Console.WriteLine(ex.InnerException);
}
catch (System.Data.Entity.Core.EntityCommandCompilationException ex)
{
Console.WriteLine(ex.InnerException);
}
catch (System.Data.Entity.Core.UpdateException ex)
{
Console.WriteLine(ex.InnerException);
}
catch (System.Data.Entity.Infrastructure.DbUpdateException ex) //DbContext
{
Console.WriteLine(ex.InnerException);
}
catch (Exception ex)
{
Console.WriteLine(ex.InnerException);
throw;
}
I know the question is old now, but I hope someone finds this useful, too.