I know few similar questions like this has been asked before in SO. But my question is little different. I have a code block similar to this -
using (DBWebEntities db = new DBWebEntities())
{
if (StatusDict != null && StatusDict.Count > 0)
{
foreach (KeyValuePair<string, job_status> kvp in JobStatusDict)
{ db.AddToEmp_status(kvp.Value); }
db.SaveChanges();
}
}
As you can see, I am running the db.saveChanges() together for all the insert queries at the end. I am getting the exception for some of the entities. How do I figure out from the exception its happening exactly for which Entity value?
As I checked the innerexception I could only find the stack trace not the entity which caused this.
I am using .NET 4.
This how I finally found it out. Hover over 'ex'-> expand System.Data.UpdateException -> Expand 'State Entries' - here you can see a the objects causing this error.