Reputation: 272
An error occurred while updating the entries. See the inner exception for details.
Inner exception : "An error occurred while preparing the command definition. See the inner exception for details."
I'm using Oracle as Entity Framework and Database. When i am trying get result using EF it's working fine. But when i am trying to insert a record into the table I am getting this issue. This is the code:
try{
Table1 Obj = new Table1();
Obj.col1 = 2010;
Obj.col2 =0;
Obj.col3 = 103907;
Obj.col4 = 14145;
DataContext1 dbContext = new DataContext1();
dbContext.AddToTable1(Obj);
dbContext.ObjectStateManager.ChangeObjectState(Obj,System.Data.EntityState.Added);
dbContext.SaveChanges();
}catch(Expectation ex)
{
}
Upvotes: 1
Views: 14125
Reputation: 6425
You need to look at the inner exception. The issue will probably be obvious from there.
Something like this might help (or set a breakpoint and just look):
try{
Table1 Obj = new Table1();
Obj.col1 = 2010;
Obj.col2 =0;
Obj.col3 = 103907;
Obj.col4 = 14145;
DataContext1 dbContext = new DataContext1()
dbContext.AddToTable1(Obj);
dbContext.ObjectStateManager.ChangeObjectState(Obj,System.Data.EntityState.Added);
dbContext.SaveChanges();
}
catch (System.Data.Entity.Validation.DbEntityValidationException e)
{
string validationErrors = "DbEntityValidationException ValidationErrors: ";
foreach (var k in e.EntityValidationErrors)
{
foreach (var e1 in k.ValidationErrors)
{
validationErrors += string.Format("{0} - {1}; ", e1.PropertyName, e1.ErrorMessage);
}
}
throw new Exception(validationErrors, e);
}
Upvotes: 1