コード例 #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();
     }
 }