public void Seed() { _ctx.Database.EnsureCreated(); if (!_ctx.Products.Any()) { // Need to create sample data var filepath = Path.Combine(_hosting.ContentRootPath, "Data/art.json"); var json = File.ReadAllText(filepath); var products = JsonConvert.DeserializeObject <IEnumerable <Product> >(json).ToList(); _ctx.Products.AddRange(products); var order = new Order { OrderDate = DateTime.Now, OrderNumber = "12345", Items = new List <OrderItem> { new OrderItem { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } } }; _ctx.AddRange(order); _ctx.SaveChanges(); } }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }