Пример #1
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     var dbContext = new ShopDbContext();
     Database.SetInitializer(new DataInitialisation());
     dbContext.Database.Initialize(true);
 }
Пример #2
0
        public static void Initialize(ShopDbContext context)
        {
            var products =
                new Product[]
            {
                new Product {
                    Id = 1, Name = "Product1", Price = 25, OrderId = 1, Order = new Order {
                        Id = 1, Cost = 60, Products = new List <Product> {
                            new Product {
                                Id = 1, Name = "Product1", Price = 25
                            },
                            new Product {
                                Id = 2, Name = "Product2", Price = 30
                            },
                        }
                    }
                },
                new Product {
                    Id = 2, Name = "Product2", Price = 30, OrderId = 2
                },
                new Product {
                    Id = 3, Name = "Product3", Price = 35, OrderId = 2
                }
            };

            foreach (Product p in products)
            {
                context.Products.Add(p);
            }
            context.SaveChanges();

            var orders =
                new Order[]
            {
                new Order {
                    Id = 1, Cost = 55, Products = new List <Product> {
                        new Product {
                            Id = 1, Name = "Product1", Price = 25
                        },
                        new Product {
                            Id = 2, Name = "Product2", Price = 30
                        },
                    }
                },
                new Order {
                    Id = 2, Cost = 65, Products = new List <Product> {
                        new Product {
                            Id = 2, Name = "Product2", Price = 30
                        },
                        new Product {
                            Id = 3, Name = "Product3", Price = 35
                        }
                    }
                }
            };

            foreach (Order o in orders)
            {
                context.Orders.Add(o);
            }
            context.SaveChanges();
        }
Пример #3
0
 public RepositoryBase(ShopDbContext shopDbContext)
 {
     this.ShopDbContext = shopDbContext;
 }