Introduction
I have already explained very known an entity framework error Validation failed for one or more entities, today providing a resolution of another entity framework error. Yesterday, I was working on MVC application using Entity Framework, meanwhile I was setting up my code then a new error comes off me "Store update, insert, or delete statement affected an unexpected number of rows". After my deep study, then came up a perfect solution to remove this issue permanently from my solution. I have explained all steps as given below.
Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries.
Error Description
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.
Fix Entity Framework Error |
Steps to Remove Error [Store update, insert, or delete statement affected an unexpected]
Set update mode to add, it was earlier set to modified state using entity framework. If table primary key greater than zero then it will modified otherwise it will add a new record in database table.Wrong Statement
I had written given below wrong statement to add a new fresh record into my database table record, it was wrongly added state to Modified._context.Entry(model).State = EntityState.Modified;
Post A Comment:
0 comments: