Esempio n. 1
0
        static void OhMy()
        {
            var db     = new SafariVacationContext();
            var furrys = db.Safaris.Where(Safari => Safari.Species == "lion" || Safari.Species == "tiger" || Safari.Species == "bears").Sum(Safari => Safari.CountOfTimesSeen);

            Console.WriteLine(furrys);
        }
Esempio n. 2
0
        static void AnimalCount()
        {
            var db    = new SafariVacationContext();
            var total = db.Safaris.Sum(Safari => Safari.CountOfTimesSeen);

            Console.WriteLine(total);
        }
Esempio n. 3
0
        static void UpdateData()
        {
            var db            = new SafariVacationContext();
            var countToUpdate = db.Safaris.FirstOrDefault(safari => safari.Species == "snakes");

            countToUpdate.CountOfTimesSeen   = 13;
            countToUpdate.LocationOfLastSeen = "jungle";
            db.SaveChanges();
        }
Esempio n. 4
0
        static void DeleteData()
        {
            var db = new SafariVacationContext();

            //   var desertDelete = db.Safaris.FirstOrDefault(safari => safari.LocationOfLastSeen == "desert");
            //   db.Safaris.Remove(desertDelete);

            var oops = db.Safaris.FirstOrDefault(Safari => Safari.Species == "bears");

            db.Safaris.Remove(oops);
            db.SaveChanges();
        }
Esempio n. 5
0
        static void ReadData()
        {
            var db = new SafariVacationContext();

            var allJungle = db.Safaris
                            .Where(Safari => Safari.LocationOfLastSeen == "jungle")
                            .Select(safari => safari.Species);

            foreach (var animal in allJungle)
            {
                Console.WriteLine(animal);
            }
        }
Esempio n. 6
0
        static void CreateData()
        {
            var db = new SafariVacationContext();

            var lion = new Safari
            {
                Species            = "lion",
                CountOfTimesSeen   = 3,
                LocationOfLastSeen = "Savannah",
            };

            var tiger = new Safari
            {
                Species            = "tiger",
                CountOfTimesSeen   = 6,
                LocationOfLastSeen = "jungle",
            };
            var bears = new Safari
            {
                Species            = "bears",
                CountOfTimesSeen   = 9,
                LocationOfLastSeen = "forest",
            };
            var snakes = new Safari
            {
                Species            = "snakes",
                CountOfTimesSeen   = 12,
                LocationOfLastSeen = "desert",
            };

            db.Safaris.Add(lion);
            db.Safaris.Add(tiger);
            db.Safaris.Add(bears);
            db.Safaris.Add(snakes);
            db.SaveChanges();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            var db = new SafariVacationContext();


            // db.Animal.Add(new SeenAnimals
            //   {
            //     Species = "Elephant",
            //     CountOfTimesSeen = 3,
            //     LocationOfLastSeen = "Desert"
            //   });
            //   db.SaveChanges();
            //   db.Animal.Add(new SeenAnimals
            //   {
            //     Species = "Lion",
            //     CountOfTimesSeen = 1,
            //     LocationOfLastSeen = "Desert"
            //   });
            //   db.SaveChanges();
            //   db.Animal.Add(new SeenAnimals
            //   {
            //     Species = "Tiger",
            //     CountOfTimesSeen = 5,
            //     LocationOfLastSeen = "Desert"
            //   });
            //   db.SaveChanges();
            //   db.Animal.Add(new SeenAnimals
            //   {
            //     Species = "Bear",
            //     CountOfTimesSeen = 7,
            //     LocationOfLastSeen = "Jungle"
            //   });
            //   db.SaveChanges();
            //   db.Animal.Add(new SeenAnimals
            //   {
            //     Species = "Zebra",
            //     CountOfTimesSeen = 12,
            //     LocationOfLastSeen = "Desert"
            //   });
            //   db.SaveChanges();
            //   db.Animal.Add(new SeenAnimals
            //   {
            //     Species = "Rhino",
            //     CountOfTimesSeen = 9,
            //     LocationOfLastSeen = "desert"
            //   });
            //   db.SaveChanges();

            Console.WriteLine("Let's go on a Safari!");
            Console.WriteLine("Wow you've seen...");


            var alreadySeen = db.Animal.OrderBy(SeenAnimals => SeenAnimals.Species);

            foreach (var SeenAnimals in alreadySeen)
            {
                Console.WriteLine($"{SeenAnimals.Species}");
            }
            Console.WriteLine(":=========================:");

            // var elephant = db.Animal.FirstOrDefault(SeenAnimals => SeenAnimals.Species == "Elephant");
            // elephant.CountOfTimesSeen = elephant.CountOfTimesSeen + 2;
            // db.SaveChanges();

            // var e = db.Animal.FirstOrDefault(SeenAnimals => SeenAnimals.Species == "Elephant");
            // elephant.LocationOfLastSeen = "Sahara";
            // db.SaveChanges();

            var j = db.Animal.Where(SeenAnimals => SeenAnimals.LocationOfLastSeen == "Jungle");

            foreach (var SeenAnimals in j)
            {
                Console.WriteLine($"{SeenAnimals.Species}");
            }

            // var desertAnimals = db.Animal.Where(SeenAnimals => SeenAnimals.LocationOfLastSeen == "Desert");
            // db.Animal.RemoveRange(desertAnimals);
            // db.SaveChanges();
        }