示例#1
0
        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}"));
        }
示例#2
0
 static void updateRabbits(int rabbitID)
 {
     using (var db = new RabbitDbContext())
     {
         var rabbit = db.Rabbits.Find(rabbitID);
         rabbit.RabbitAge++;
         db.Rabbits.Update(rabbit);
         db.SaveChanges();
     }
 }
示例#3
0
 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();
     }
 }
示例#4
0
 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();
     }
 }