1

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?

5
  • How does the school object look like? Commented Jun 1, 2015 at 19:14
  • @McBoman what exactly about the school object you want to know..the structure or...? Thanks Commented Jun 1, 2015 at 19:16
  • 2
    possible duplicate of Entity Framework - Optimistic Concurrency Issue Commented Jun 1, 2015 at 19:19
  • More if all the needed data is filled out. Commented Jun 1, 2015 at 19:21
  • @McBoman fyi, when I'm executing the same query which is generated from EF and is visible in the Sql Profiler via SSMS I'm getting no errors. Is that helping you? Thanks Commented Jun 1, 2015 at 20:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.