public static void SetupDatabase(CudContext context) { using (context) { context.Database.EnsureCreated(); if (!context.Set <Customer>().Any()) { InsertTestingData(context); } //clear the SQL Server plan cache //TODO: context.ExecuteStoreCommand("DBCC FREEPROCCACHE WITH NO_INFOMSGS;"); } }
public static void InsertTestingData(CudContext context) { for (var i = 0; i < 10; i++) { var customer = new Customer { Name = "Customer" }; for (var j = 0; j < 5; j++) { var order = new Order { Date = DateTime.Now }; for (var k = 0; k < 1; k++) { var orderLine = new OrderLine { Price = 123.45m, Quantity = 42, Product = k % 2 == 0 ? new Product { Name = "Product" } : new SpecialProduct { Name = "SpecialProduct", Style = "Cool" } }; order.OrderLines.Add(orderLine); } customer.Orders.Add(order); } context.Customers.Add(customer); context.SaveChanges(); } }