Beispiel #1
0
 public static void Initialize(ProductsDbContext context)
 {
     context.Database.EnsureCreated();
     if (context.Products.Any())
     {
         return; //DB has been seeded
     }
     context.Products.AddRange(
         new Product
     {
         Name        = "Usbcable",
         Description = "Yellow",
         Category    = "Electronics",
         Price       = 5
     },
         new Product
     {
         Name        = "Laptop",
         Description = "Asus",
         Category    = "Electronics",
         Price       = 5030
     }
         );
     context.SaveChanges();
 }
Beispiel #2
0
        public static void Initialize(ProductsDbContext context)
        {
            context.Database.EnsureCreated();

            // Look for any Products.
            if (context.Products.Any())
            {
                return;   // DB has been seeded
            }

            context.Products.AddRange(
                new Product
            {
                Name        = "Wine",
                Description = "White, Yellow",
                Category    = "Drinks",
                Price       = 25.2
            },
                new Product
            {
                Name        = "Coca",
                Description = "Black, Cola",
                Category    = "Drinks",
                Price       = 2.2
            }
                );
            context.SaveChanges();
        }