Apress Pro Asp.net MVC Framework 3 - SportsStore Edit Product not working?

后端 未结 7 2056
慢半拍i
慢半拍i 2021-02-13 23:33

G’day All, has anyone purchased the ALPHA of Apress Pro Asp.net MVC Framework 3 and created the SportsStore? I can’t for the life of me edit products and have the DB update suc

7条回答
  •  一生所求
    2021-02-13 23:44

    Here is the answer

    public void SaveProduct(Product product)
        {
            var prod = context.Products.SingleOrDefault(p => p.ProductID == product.ProductID);
    
            if (product.ProductID > 0)
            {
                context.Products.Remove(prod);
            }
                context.Products.Add(product);            
                context.SaveChanges();
        }
    

提交回复
热议问题