I'm trying to add a new record to the entity framework and I'm getting this error when adding the record:
An exception of type 'System.Data.OptimisticConcurrencyException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
This is the code I have (note: I'm getting the same exception in both the try/catch block):
try
{
AppBLL.Context.Schools.AddObject(school);
AppBLL.Context.SaveChanges();
}
catch (OptimisticConcurrencyException ex)
{
AppBLL.Context.Refresh(RefreshMode.StoreWins, AppBLL.Context.Schools);
AppBLL.Context.SaveChanges();
}
Any idea what am I doing wrong?