Example #1
0
 static void listRabbits()
 {
     using (var db = new RabbitDbContext())
     {
         rabbits = db.Rabbits.ToList();
     }
     rabbits.ForEach(r => Console.WriteLine($"{r.RabbitId,-10}{r.RabbitName,-20}{r.Age}"));
 }
Example #2
0
 static void updateRabbit()
 {
     //  updateRabbit(rabbit);
     using (var db = new RabbitDbContext())
     {
         var rabbitToUpdate = db.Rabbits.Find(3);
         rabbitToUpdate.RabbitName = "Rabbit3 has a new name";
         db.SaveChanges();
     }
 }
Example #3
0
 static void addRabbit()
 {
     using (var db = new RabbitDbContext())
     {
         var rabbit = new Rabbit(3, "Rabbit3", 0);
         // add to database
         db.Rabbits.Add(rabbit);
         db.SaveChanges();
     }
 }
Example #4
0
        static void Main(string[] args)
        {
            using (var db = new RabbitDbContext())
            {
                //for (int i = 0; i < 99; i++)
                //{
                //    Rabbit r = NewRabbit();
                //    db.Add(r);
                //}
                //db.SaveChanges();
                //rabbits = db.RabbitsTable.ToList();
                while (true)
                {
                    rabbits = listRabbits(db);
                    updateRabbit(db);
                    addRabbit(db);

                    rabbits = listRabbits(db);
                    PrintRabbit(rabbits);
                }
            }
        }
Example #5
0
 public static List <Rabbit> listRabbits(RabbitDbContext db)
 {
     return(db.RabbitsTable.ToList());
 }