Beispiel #1
0
        private void CreateData(Db.ProductsDbContext dbContext)
        {
            for (int i = 1; i <= 10; i++)
            {
                var product = new Db.Product(i, $"Product-{i}", i * 3.14M, 100);
                dbContext.Products.Add(product);
            }

            dbContext.SaveChanges();
        }
 private void SeedData()
 {
     if (!dbContext.Products.Any())
     {
         dbContext.Products.Add(new Db.Product()
         {
             Id = 1, Name = "Keyboard", Price = 20, Inventory = 100
         });
         dbContext.Products.Add(new Db.Product()
         {
             Id = 2, Name = "Mouse", Price = 5, Inventory = 200
         });
         dbContext.Products.Add(new Db.Product()
         {
             Id = 3, Name = "Monitor", Price = 150, Inventory = 1000
         });
         dbContext.Products.Add(new Db.Product()
         {
             Id = 4, Name = "CPU", Price = 200, Inventory = 2000
         });
         dbContext.SaveChanges();
     }
 }
Beispiel #3
0
 private void SeedData()
 {
     if (!dbContext.Products.Any())
     {
         dbContext.Products.Add(new Db.Product()
         {
             Id = 1, Name = "Zapatos", Price = 20, Inventory = 100
         });
         dbContext.Products.Add(new Db.Product()
         {
             Id = 2, Name = "Sombrero", Price = 5, Inventory = 200
         });
         dbContext.Products.Add(new Db.Product()
         {
             Id = 3, Name = "Camisa", Price = 150, Inventory = 1000
         });
         dbContext.Products.Add(new Db.Product()
         {
             Id = 4, Name = "Pantalón", Price = 200, Inventory = 2000
         });
         dbContext.SaveChanges();
     }
 }