using EF_ChangeLog.Controller; using EF_ChangeLog.Model; namespace EF_ChangeLog { internal class Program { static void Main(string[] args) { using (var context = new StockDbContext()) { // Create samples Random rand = new Random(); List newStocks = new List() { new Stock() { Name = $"Test Stock{rand.Next(1, 1000)}", Price = 1000 }, new Stock() { Name = $"Test Stock{rand.Next(1, 1000)}", Price = 1000 }, new Stock() { Name = $"Test Stock{rand.Next(1, 1000)}", Price = 1000 }, new Stock() { Name = $"Test Stock{rand.Next(1, 1000)}", Price = 1000 } }; foreach (var newStock in newStocks) { newStock.SaveSnapshot(); context.Stocks.Add(newStock); } context.SaveChanges(); // Update sample var stock = context.Stocks.Find(rand.Next(1, 5)); if (stock != null) { stock.Price = rand.Next(1, 10) * 1000; stock.SaveSnapshot(); context.SaveChanges(); } // Delete sample var del = context.Stocks.OrderByDescending(s => s.Id).FirstOrDefault(); if (del != null) { context.Stocks.Remove(del); del.SaveSnapshot(); context.SaveChanges(); } } } } }