Ejemplo n.º 1
0
        // This method will create and seed the database.
        public void Initialize(OrderApiContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

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

            List <Order> orders = new List <Order>
            {
                new Order {
                    Date = DateTime.Today, ProductId = 1, Quantity = 2
                }
            };

            context.Orders.AddRange(orders);
            context.SaveChanges();
        }
 public OrderRepository(OrderApiContext context)
 {
     db = context;
 }