コード例 #1
0
 public static List <Trinket> readFromDataBaseToList()
 {
     using (var db = new TrinketsContext())
     {
         return(db.TrinketsDataBase.ToList());
     }
 }
コード例 #2
0
 public static void SeedDataBase()
 {
     using (var db = new TrinketsContext())
     {
         db.Database.EnsureCreated();
     }
 }
コード例 #3
0
 public static void ReadFromDataBase()
 {
     using (var db = new TrinketsContext())
     {
         foreach (var t in db.TrinketsDataBase)
         {
             Console.WriteLine(string.Format("Name: {0, -230} Price: JPY {1, -15:N} Discount: {2, -15}", t.ProductName, t.ProductPrice, t.ProductDiscount));
         }
     }
 }
コード例 #4
0
 public static void ReadFromDataBaseFiltered()
 {
     using (var db = new TrinketsContext())
     {
         var trinkets = db.TrinketsDataBase.Where(b => b.ProductName.Contains("Bunny"));
         foreach (var t in trinkets)
         {
             Console.WriteLine(string.Format("Name: {0, -230} Price: JPY {1, -15:N} Discount: {2, -15}", t.ProductName, t.ProductPrice, t.ProductDiscount));
         }
     }
 }
コード例 #5
0
 public static void WriteToDataBase(string productName, string productLink, double productPrice, string productDiscount)
 {
     using (var db = new TrinketsContext())
     {
         db.TrinketsDataBase.Add(new Trinket()
         {
             ProductName = productName, ProductLink = productLink, ProductPrice = productPrice, ProductDiscount = productDiscount
         });
         db.SaveChanges();
     }
 }