예제 #1
0
        internal static void EfInMemory()
        {
            Console.WriteLine("EF in memory");
            using (var db = new InMemory())
            {
                db.AddRange(
                    new Foo {
                    Text = "1"
                },
                    new Foo {
                    Text = "2"
                },
                    new Foo {
                    Text = "3"
                },
                    new Foo {
                    Text = "4"
                });
                db.SaveChanges();

                var sw   = Stopwatch.StartNew();
                var foos = db.Foos.ToList();
                sw.Stop();
                Console.WriteLine($"Selecting {foos.Count} items took {sw.ElapsedMilliseconds:N1} ms.");

                sw.Restart();
                foos = db.Foos.ToList();
                sw.Stop();
                Console.WriteLine($"Selecting {foos.Count} items took {sw.ElapsedMilliseconds:N1} ms.");
            }
        }
        internal static void EfInMemory()
        {
            Console.WriteLine("EF in memory");
            using (var db = new InMemory())
            {
                db.AddRange(
                    new Foo {
                    Text = "1"
                },
                    new Foo {
                    Text = "2"
                },
                    new Foo {
                    Text = "3"
                },
                    new Foo {
                    Text = "4"
                });
                db.SaveChanges();

                var sw    = Stopwatch.StartNew();
                var first = db.Foos.First(x => x.Text == "1");
                sw.Stop();
                Console.WriteLine($"Selecting item {first.Id} took {sw.ElapsedMilliseconds:N1} ms.");

                sw.Restart();
                first = db.Foos.First(x => x.Text == "2");
                sw.Stop();
                Console.WriteLine($"Selecting item {first.Id} took {sw.ElapsedMilliseconds:N1} ms.");

                sw.Restart();
                first = db.Foos.First(x => x.Text == "3");
                sw.Stop();
                Console.WriteLine($"Selecting item {first.Id} took {sw.ElapsedMilliseconds:N1} ms.");

                sw.Restart();
                first = db.Foos.First(x => x.Text == "4");
                sw.Stop();
                Console.WriteLine($"Selecting item {first.Id} took {sw.ElapsedMilliseconds:N1} ms.");
            }
        }