During reading "Pro ASP.NET MVC 3 Framework" by Steven Sanderson, Adam Freeman I found that my code doesn't working (Chapter 9, page 267). There is the Repository method called SaveChanges and it doesn't work for me. The code is defined like below:
public void SaveProduct(Product product) {In order to get it working you need to change it:
if (product.ProductID == 0) {
context.Products.Add(product);
}
context.SaveChanges();
}
public void SaveProduct(Product product)Hope this would help others in learning MVC using this incredible book!
{
if (product.ProductID == 0)
{
m_Context.Products.Add(product);
}
else
{
m_Context.Entry(product).State = System.Data.EntityState.Modified;
}
m_Context.SaveChanges();
}