static void PrintRabbits() { using (var db = new RabbitDbContext()) { Rabbits = db.Rabbits.ToList(); } Rabbits.ForEach(c => Console.WriteLine($"{c.RabbitID,-10}{c.RabbitName,-30}{c.RabbitAge,-40}")); }
static void updateRabbits(int rabbitID) { using (var db = new RabbitDbContext()) { var rabbit = db.Rabbits.Find(rabbitID); rabbit.RabbitAge++; db.Rabbits.Update(rabbit); db.SaveChanges(); } }
static void updateRabbitAge() { using (var db = new RabbitDbContext()) { Rabbits = db.Rabbits.ToList(); foreach (var age in Rabbits) { age.RabbitAge++; db.Rabbits.Update(age); } db.SaveChanges(); } }
static void addRabbits() { using (var db = new RabbitDbContext()) { for (int i = 0; i < 10; i++) { var rabbit = new Rabbit("Rabbit" + i, 0); db.Rabbits.Add(rabbit); updateRabbitAge(); } db.SaveChanges(); } }