static void listRabbits() { using (var db = new RabbitDbContext()) { rabbits = db.Rabbits.ToList(); } rabbits.ForEach(r => Console.WriteLine($"{r.RabbitId, -10}{r.RabbitName,-20}{r.RabbitAge}")); }
static void updateRabbit() { using (var db = new RabbitDbContext()) { var rabbitsToUpdate = db.Rabbits.Find(41); rabbitsToUpdate.RabbitName = "Pichu"; rabbitsToUpdate.RabbitAge = 14; db.SaveChanges(); } }
static void addRabbit() { using (var db = new RabbitDbContext()) { for (int i = 0; i < 10; i++) { var newRabbit = new Rabbit("Rabbit", 0); newRabbit.RabbitName = newRabbit.RabbitName + i; newRabbit.RabbitAge = newRabbit.RabbitAge + i + 1; var complete = new Rabbit(newRabbit.RabbitName, newRabbit.RabbitAge); db.Rabbits.Add(complete); } db.SaveChanges(); } }