none
save changes in app MVC with Entity Framework RRS feed

  • Question

  • Hi.

    I have a problem with my app, initially my app worked correctly and later send this error:

    System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.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.

    please helpme.

    it´s so important.

    thanks.

    Wednesday, April 22, 2015 3:42 PM

All replies

  • Hi krloz.hdz,

    -->System.Data.Entity.Infrastructure.DbUpdateConcurrencyException' occurred in EntityFramework.dll but was not handled in user code

    this error offen occurs at the SaveChanges(). I suggest you change the state of the entity like below before savechanges().

    db.overlayData.Attach(overlaydb1);
          db.ObjectStateManager.ChangeObjectState(overlaydb1, EntityState.Modified);
          db.SaveChanges();

    If you still have questions, you could share your code with us, we could help you better.

    Regards,
    Youjun Tang


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, April 23, 2015 9:09 AM
  • I really don't know what you were trying to do concerning an insert, update or delete of an entity or entities, but the expected results of the action or the resutls of the executed T-SQL the ORM geberated resulted in 0 records were affected -- nothing happened, and EF is going to throw the execption behind it letting you know that nothing happened.

    You can do the same kind of thing with an insert, update or delete using T-SQL and see this in MS SQL Server Studio Managaer when executing the T-SQL. If nothing really happened, you are going to get back a message of "0 rows were afffected" if the T-SQL executed resulted in no rows being affected, which would be a visual clue telling you that it did not happen.

    Now what's wrong with your insert, update or delete of the entity or entities that resulted in T-SQL being executed with 0 rows affected is something you are going to have to find out why that is happening.

    Thursday, April 23, 2015 2:46 PM