Inserting, updating, and deleting entities using EF Core is easy.
In Program
, create a new method named AddProduct
, as shown in the following code:
static bool AddProduct(int categoryID, string productName, decimal? price) { using (var db = new Northwind()) { var newProduct = new Product { CategoryID = categoryID, ProductName = productName, Cost = price }; // mark product as added in change tracking db.Products.Add(newProduct); // save tracked changes to database int affected = db.SaveChanges(); return (affected == 1); } }
In Program
, create a new method named ListProducts
, as shown in the following code:
static void ListProducts() { using (var db = new Northwind()) { WriteLine("--------------------------------------------------------- ---------------"); WriteLine("| ID | Product Name | Cost | Stock | Disc. |"); WriteLine...