public void SetInventory(int productId, int quantity) { var prod = GetProductById(productId); using (MySqlProductsDb Db = new MySqlProductsDb(ConnectionString)) { if (prod != null) { Db.Products.Attach(prod); prod.Inventory = quantity; Db.Entry(prod).Property("Inventory").IsModified = true; Db.SaveChanges(); } } }