示例#1
0
 public string GetProductName(int productID)
 {
     using (var products = new ProductsContext())
     {
         return(products.Products.FirstOrDefault(x => x.ProductID == productID)?.ProductName);
     }
 }
示例#2
0
 public int?GetProductQty(int productID)
 {
     using (var products = new ProductsContext())
     {
         return(products.Products.FirstOrDefault(x => x.ProductID == productID)?.UnitInStock);
     }
 }
示例#3
0
 public int?GetCategoryID(int productID)
 {
     using (var products = new ProductsContext())
     {
         return(products.Products.FirstOrDefault(x => x.ProductID == productID)?.CategoryID);
     }
 }
示例#4
0
 public void AddNewProduct()
 {
     using (var products = new ProductsContext())
     {
         products.Products.Add(new Product()
         {
             ProductID = 1, ProductName = "C# 6 with Visual Studio", CategoryID = 2, CategoryName = "books", UnitInStock = 100
         });
         products.SaveChanges();
     }
 }