public void Seed() { _ctx.Database.EnsureCreated(); if (!_ctx.Products.Any()) { // Need to create the Sample Data var file = Path.Combine(_hosting.ContentRootPath, "Data/art.json"); var json = File.ReadAllText(file); var products = JsonSerializer.Deserialize <IEnumerable <Product> >(json); _ctx.Products.AddRange(products); var order = _ctx.Orders.Where(o => o.Id == 1).FirstOrDefault(); if (order != null) { order.Items = new List <OrderItem>() { new OrderItem() { Product = products.First(), Quantity = 5, UnitPrice = products.First().Price } }; } _ctx.SaveChanges(); } }
public bool SaveAll() { return(_ctx.SaveChanges() > 0); }