static void UpdateData() { var db = new SafariVacationContext(); var countToUpdate = db.Safaris.FirstOrDefault(safari => safari.Species == "snakes"); countToUpdate.CountOfTimesSeen = 13; countToUpdate.LocationOfLastSeen = "jungle"; db.SaveChanges(); }
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(); }
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(); }