I am using Visual Studio 2012. I have a very simple product table in a local database (artfully named Database1). It has two fields: id and Name. I preloaded it with some test data.
The following code should update the name of the first product. Inside it is. I can get all the products and see that the first name is "Shirt." But this change is never flushed to the database. The record is never updated. Examining the database shows that the name has not been changed.
My question is simple: why the changes are not sent to the database?
using (var context = new Database1Entities()) { var products = context.Products; products.First().Name = "Shirt"; context.SaveChanges(); }
Thanks in advance.
= - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - =
EDIT:
I tried my best to enter the full code and output it here. But no matter what I do, I keep getting the error message "Your message seems to contain code that is not formatted correctly." After 30 minutes I give up.
EDIT:
Code and output here: http://pastebin.com/GmQtwAND
source share