private void удалитьМодельToolStripMenuItem_Click(object sender, EventArgs e) { try { db.Options.RemoveRange(product.Options); db.Products.Remove(product); db.SaveChanges(); UpdateDate(); } catch (Exception) {} }
protected void CleanupPriceContext() { var db = new PriceContext(); db.Prices.RemoveRange(db.Prices.ToArray()); db.SaveChanges(); }
public void ZeroShouldNotMatchNullWhenSelectExisting() { using (var db = new PriceContext()) { db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 1), Name = "ERICB", Value = 80 }); db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 2), Name = "ERICB", Value = 81 }); db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 3), Name = "ERICB", Value = 82 }); db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 4), Name = "ERICB", Value = 0 }); db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 5), Name = "ERICB", Value = 86 }); db.SaveChanges(); var prices = new[] { db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 1), Name = "ERICB", Value = 80 }), db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 2), Name = "ERICB", Value = 81 }), db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 3), Name = "ERICB", Value = 82 }), db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 4), Name = "ERICB", Value = null }), db.Prices.Add(new Price() { Date = new DateTime(2019, 1, 5), Name = "ERICB", Value = 86 }) }; var existing = db.BulkSelectExisting <Price, Price>( new BulkSelectRequest <Price>(new[] { "Date", "Name", "Value" }, prices)); Assert.AreEqual(4, existing.Count); Assert.AreSame(prices[0], existing[0]); Assert.AreSame(prices[1], existing[1]); Assert.AreSame(prices[2], existing[2]); Assert.AreSame(prices[4], existing[3]); } }
public static void SeedQuestions(PriceContext context) { if (!context.Pitanja.Any()) { var pitanjaData = System.IO.File.ReadAllText("../SeedData/Data/PitanjaSeedJson.json"); var pitanja = JsonConvert.DeserializeObject <List <Pitanje> >(pitanjaData); foreach (var prica in pitanja) { context.Pitanja.Add(prica); } context.SaveChanges(); } }
public static void SeedPrice(PriceContext context) { if (!context.Price.Any()) { var priceData = System.IO.File.ReadAllText("../SeedData/Data/PriceSeedJson.json"); var price = JsonConvert.DeserializeObject <List <Prica> >(priceData); foreach (var prica in price) { context.Price.Add(prica); } context.SaveChanges(); } }
private void InitializeDatabase() { var priceContext = new PriceContext(); priceContext.Database.EnsureCreated(); if (priceContext.ProductPrices.Any()) { return; } for (int i = 0; i <= 6; i++) { priceContext.ProductPrices.Add(new ProductPrice(i * 100, i + 10)); } priceContext.SaveChanges(); }