public void TestLazyLoadBookAndReviewUsingProxiesPackageOk() { //SETUP var options = CreateOptionsLazyLoadingProxies <Lazy2DbContext>(); using (var context = new Lazy2DbContext(options)) { context.Database.EnsureCreated(); var book = new BookLazy2 { Reviews = new List <LazyReview> { new LazyReview { NumStars = 5 }, new LazyReview { NumStars = 1 } } }; context.Add(book); context.SaveChanges(); } using (var context = new Lazy2DbContext(options)) { //ATTEMPT var book = context.BookLazy2s.Single(); //#A book.Reviews.Count().ShouldEqual(2); //#B /********************************************************* #A We just load the book class #B When the Reviews are read, then EF Core will read in the reviews * *******************************************************/ } }
public void TestLazyLoadBookAndReviewUsingActionOk() { //SETUP var showlog = false; var options = SqliteInMemory.CreateOptionsWithLogging <LazyInjectContext>(log => { if (showlog) { _output.WriteLine(log.Message); } }); using (var context = new LazyInjectContext(options)) { context.Database.EnsureCreated(); var book = new BookLazy2 { Promotion = new PriceOffer { NewPrice = 5 }, Reviews = new List <Lazy2Review> { new Lazy2Review { NumStars = 5 }, new Lazy2Review { NumStars = 1 } } }; context.Add(book); context.SaveChanges(); } using (var context = new LazyInjectContext(options)) { //ATTEMPT showlog = true; var book = context.BookLazy2s.Single(); var reviews = book.Reviews.ToList(); //VERIFY book.Promotion.ShouldBeNull(); context.BookLazy2s.Select(x => x.Promotion).ShouldNotBeNull(); reviews.Count.ShouldEqual(2); } }