Exemplo n.º 1
0
        private static void InitialzieOrderProducts()
        {
            using (var context = new OrderProductDbContext())
            {
                // Look for any Customerss.
                if (context.OrderProducts.Any())
                {
                    return;   // DB has been seeded
                }

                context.OrderProducts.AddRange(
                    new List <OrderProduct>()
                {
                    new OrderProduct
                    {
                        OrderId   = 1,
                        ProductId = 1,
                        Quantity  = 5
                    },
                    new OrderProduct
                    {
                        OrderId   = 1,
                        ProductId = 2,
                        Quantity  = 3
                    }
                }
                    );
                context.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public static void CleanUp()
        {
            using (var context = new CustomerDbContext())
            {
                var all = context.Customers.ToList();
                context.Customers.RemoveRange(all);
                context.SaveChanges();
            }

            using (var context = new OrderDbContext())
            {
                var all = context.Orders.ToList();
                context.Orders.RemoveRange(all);
                context.SaveChanges();
            }

            using (var context = new ProductDbContext())
            {
                var all = context.Products.ToList();
                context.Products.RemoveRange(all);
                context.SaveChanges();
            }

            using (var context = new OrderProductDbContext())
            {
                var all = context.OrderProducts.ToList();
                context.OrderProducts.RemoveRange(all);
                context.SaveChanges();

                context.Database.Delete();
                context.SaveChanges();
            }
        }