private void Demo_02_LazyLoading() { //Now we're taking all of the ceremony stuff we //did by hand in demo 1 and moving it into our repository var dRepo = new DinosaurRepository(); var dino = dRepo.GetDinosaurByName("Tyrannosaurus Rex"); //dRepo.Dispose(); //<-- Observing a property in the debugger will make it lazy load! var rider = dino.Riders.First(); //<-- Touching a property will cause lazy loading dRepo.Dispose(); //<-- Observing a property in the debugger will make it lazy load! }
private void Deleting_Adding_and_Changing_with_a_Repo() { log4net.Config.XmlConfigurator.Configure(); var dRepo = new DinosaurRepository(); var cRepo = new CategoryRepository(); Dinosaur d; Console.WriteLine("****** DELETE START ********"); d = dRepo.GetDinosaurByName("AwesomeSaurus Rex"); if (d != null) dRepo.DeleteDinosaur(d); Console.WriteLine("****** DELETE END ********"); Console.WriteLine("****** ADD START ********"); d = new Dinosaur(); d.Name = "AwesomeSaurus Rex"; d.Categories.Add(cRepo.GetCategory("S3")); d.Categories.Add(cRepo.GetCategory("Rul")); d.Riders.Add(new Rider { DinoBox = d, FigImageUrl = @"/content/images/InfoPic-Rusty.jpg", Name = "Rusty" }); dRepo.SaveDinosaur(d); Console.WriteLine("****** ADD END ********"); Console.WriteLine("****** UPDATE START ********"); var dUp = dRepo.GetDinosaurByName("AwesomeSaurus Rex"); dUp.Description = "The most awesome dinosaur in the universe!"; dUp.BoxImageUrl = @"/content/images/AwesomeSaurus-Front-Small.png"; dUp.FigImageUrl = @"/content/images/InfoPic-Pterodactyl.jpg"; dUp.ThumbImageUrl = @"/content/images/NavigationPic-AwesomeSaurus"; d.Weapons.Add("None"); dRepo.SaveDinosaur(dUp); Console.WriteLine("****** UPDATE END ********"); dRepo.Dispose(); }