Entity Framework - Store update, insert, or delete statement affected an unexpected number of rows (0)
As I was creating a simple Create, Update, Delete (CRUD) application in ASP.NET MVC 5 and executing the controller on Edit, I encountered an error called "Store update, insert, or delete statement affected an unexpected number of rows (0)".
After debugging and looking at the stack trace, I found out that the value of the primary key is zero.
The fix for this issue is to add a hidden field to the edit view referencing to the primary key which in this case is the EmployeeID.
And now, the model passed to the context now has a value for the EmployeeID field.
Cheers! :)
After debugging and looking at the stack trace, I found out that the value of the primary key is zero.
Department: "Education" Designation: "Dean" EmployeeName: "JE" EmployeeID: 0 Salary: 25500
@Html.HiddenFor(model => model.EmployeeID)
Department: "Education" Designation: "Dean" EmployeeName: "JE" EmployeeID: 2 Salary: 25500
Comments
Post a Comment