public void Lazy() { var logOutputs = new List <LogOutput>(); var optionsWithLogging = SqliteInMemory.CreateOptions <Northwind_smallContext>() .WithExtension(new ProxiesOptionsExtension().WithLazyLoading()) as DbContextOptions <Northwind_smallContext>; using var context = new Northwind_smallContext(optionsWithLogging); context.Database.ExecuteSqlRaw(CreaeSqlCommands); context.SaveChanges(); SetupLogging(context, logOutputs); var stopwatch = Stopwatch.StartNew(); var order = context.Order .FirstOrDefault(o => o.Customer.CompanyName == "Vins et alcools Chevalier"); Assert.That(order, Is.Not.Null); Assert.That(order.Employee, Is.Not.Null); Assert.That(order.Customer, Is.Not.Null); Console.WriteLine(order.Customer); Console.WriteLine( $"Employee: {order?.Employee.FirstName + " " + order?.Employee.LastName} " + $"Reports to {order?.Employee?.ReportsToEmployee.FirstName + " " + order?.Employee?.ReportsToEmployee.LastName} " + $"Service {order.Customer.ContactName}." + $"BTW he also take a look a {order.Employee.EmployeeTerritories.Select(territory => territory.Territory).Count()} territories." + $"Such as: {String.Join(",", order.Employee.EmployeeTerritories .Select(et => et.Territory.TerritoryDescription + " in " + et.Territory.Region.RegionDescription))}" ); stopwatch.Stop(); Console.WriteLine("takes {0} ms ", stopwatch.ElapsedMilliseconds); Assert.That(logOutputs.Count, Is.EqualTo(13)); }
private static (Northwind_smallContext context, List <LogOutput> logs) InitialContext() { var logOutputs = new List <LogOutput>(); var optionsWithLogging = SqliteInMemory.CreateOptions <Northwind_smallContext>(); var context = new Northwind_smallContext(optionsWithLogging); context.Database.ExecuteSqlRaw(CreaeSqlCommands); context.SaveChanges(); SetupLogging(context, logOutputs); return(context, logOutputs); }