private static Context GetContext(IServiceProvider services) { if (Context == null) Context = new Context(services); Context.Stream.Reset(); return Context; }
private void LoadWorlds(int repeat, Context ctx) { var reader = ctx.BulkReader; var lazyResult = ctx.LazyWorlds; var worlds = ctx.Worlds; reader.Reset(true); for (int i = 0; i < repeat; i++) { var id = Random.Next(10000) + 1; lazyResult[i] = reader.Find<World>(IDs[id]); } reader.Execute(); for (int i = 0; i < repeat; i++) worlds[i] = lazyResult[i].Value; }
/* multiple roundtrips loading of worlds. don't write such production code */ private void LoadWorldsSlow(int repeat, Context ctx) { var worlds = ctx.Worlds; var repository = ctx.WorldRepository; for (int i = 0; i < repeat; i++) { var id = Random.Next(10000) + 1; worlds[i] = repository.Find(IDs[id]); } }