static void addData() { var db = new SafariContext(); var animalSeen = db.SeenAnimal.Sum(SeenAnimals => SeenAnimals.CountOfTimesSeen); Console.WriteLine("Number of animals seen: " + animalSeen); }
public static void DeleteData() { var db = new SafariContext(); var deleteRecord = db.Animals.FirstOrDefault(s => s.LocationOfLastSeen == "Desert"); db.SaveChanges(); }
public static void UpdateData() { var db = new SafariContext(); // var bestMovie = db.Safaris.FirstOrDefault(count => count.CountOfTimesSeen) && (count.LocationOfLastSeen) db.SaveChanges(); }
static void UpdateData() { var db = new SafariContext(); var animalToUpdate = db.SeenAnimal.FirstOrDefault(SeenAnimals => SeenAnimals.Species == "Tiger"); animalToUpdate.CountOfTimesSeen = 14; animalToUpdate.LocationOfLastSeen = "Grasslands"; db.SaveChanges(); }
static void readCountOfAnimals() { var db = new SafariContext(); var animalSeen = db.SeenAnimal .Where(SeenAnimals => SeenAnimals.Species == "Bear" || SeenAnimals.Species == "Lion" || SeenAnimals.Species == "Tiger") .Select(SeenAnimals => SeenAnimals.CountOfTimesSeen); foreach (var animal in animalSeen) { Console.WriteLine(animal); } }
static void ReadData() { var db = new SafariContext(); var animalSeen = db.SeenAnimal .Where(SeenAnimals => SeenAnimals.LocationOfLastSeen == "Jungle") .Select(SeenAnimals => SeenAnimals.Species); foreach (var animal in animalSeen) { Console.WriteLine(animal); } }
static void DeleteData() { var db = new SafariContext(); var animalToDelete = db.SeenAnimal .Where(SeenAnimals => SeenAnimals.LocationOfLastSeen == "Desert") .Select(SeenAnimals => SeenAnimals); foreach (var animal in animalToDelete) { db.SeenAnimal.Remove(animal); } db.SaveChanges(); }
public static void ReadData() { var db = new SafariContext(); var animals = db.Animals.Select(s => s); // var animals = db.Animals; foreach (var row in animals) { Console.WriteLine(String.Format("We saw {0} {1} in {2}", row.CountOfTimesSeen, row.Species, row.LocationOfLastSeen)); } }
static void CreateData() { // 1. Reference the database var db = new SafariContext(); // 2. Create a new movie var fox = new SeenAnimals { Species = "Alligator", CountOfTimesSeen = 3, LocationOfLastSeen = "Swamp" }; db.SeenAnimal.Add(fox); // 3. Save the thing db.SaveChanges(); }
public static void SumData() { var db = new SafariContext(); // var sum = db.Safaris.Aggregate(sum, s) => s.CountOfTimesSeen + sum); }
public static void ReadJungle() { var db = new SafariContext(); var allAnimalsSeen = db.Animals.Select(location => location.LocationOfLastSeen); }