This project is read-only.

EF error when updating

Oct 23, 2013 at 9:00 AM
After completing Part-6 which is Model Validation. I can create albums but when updating an existing one I encounter an error on the SaveChanges() line as following:
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.
Would really appreciate some suggestions on this.
Oct 23, 2013 at 10:19 AM
Further testing results in the conclusion that I encounter this error only when I am annotating the Album class with [Bind(Exclude = "AlbumId")]. But this has been suggested in the tutorial. I should not be encountering this problem???
Nov 5, 2013 at 9:19 PM
As I have pointed out in the 'Issues' log.

I received this error when attempting to 'save' in the 'MvcStoreManagerConroller' view 'Edit'.
The 'MvcStoreManagerController' 'HTTPPOST' 'Edit' action method is invoked.
I set up a breakpoint and examined the 'album' object container contents.
The album ID was = 0.
So the error is saying an attempt was made to update a row that did not exist.

The problem:

Why is the album ID not being pulled and stored in memory, held in the hidden control for the ID
then passed back to the controller via the album object class?

MVC has got this going on with hidden code so it seems that the answer is to fish
around for the proper setting to make sure the album ID does not get lost.

I am not a fan of generated or hidden code.
That is the difference here between ASP.NET with C#.NET and separate class libraries
where I do my own SQL and pull my own values from controls and pass them around.

No answer yet.
Nov 6, 2013 at 9:17 AM
@bofcarbon1 Exactly! Only when I annotate the Album class with [Bind (Exclude = "AlbumId")] I also found out that id=0 was always being passed.