public void SetUp2()
        {
            Spec = entitySpec.Begin()
                   .Add("Name")
                   .Add(entitySpec.Begin("Classes")
                        .Add("Name").PrimaryKey()
                        .Add(entitySpec.Begin("Students")
                             .Add("FirstName")
                             .Add("LastName")));

            var exportMem = new DataExtract <School>(Spec);

            exportMem.Run(School);
            var tables = exportMem.TableManager.GetWithAllData();

            Assert.AreEqual(1, tables.Single(_ => _.Name == "School").Rows.Count);
            Assert.AreEqual(6, tables.Single(_ => _.Name == "Classes").Rows.Count);
            Assert.AreEqual(100, tables.Single(_ => _.Name == "Students").Rows.Count);

            if (Environment.MachineName != "DAN_FACTOR10")
            {
                return;
            }
            var tableFactory = new SqlTableManager(SqlTestHelpers.ConnectionString("SchoolPkTest"));
            var exportDb     = new DataExtract <School>(Spec, tableFactory);

            SqlTestHelpers.WithNewDb("SchoolPkTest", conn =>
            {
                var sw = Stopwatch.StartNew();
                exportDb.Run(Enumerable.Range(0, 1).Select(_ => School));
                _classQueryResult = SqlTestHelpers.SimpleQuery(conn, "SELECT * FROM school_classes");
            });
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var school = new School
            {
                Name    = "Old School",
                Classes = new[] { "Klass 1a", "Klass 1b", "Klass 2a", "Klass 2b", "Klass 3a", "Klass 3b" }.Select(
                    _ => new Class {
                    Name = _, Students = new List <Student>()
                }).ToList()
            };
            var firstNames = new[] { "Ada", "Bertil", "Cecilia", "David", "Elina", "Fredrik", "Gun", "Hans", "Ida", "Jan", "Klara" };
            var lastNames  = new[] { "Johansson", "Eriksson", "Karlsson", "Andersson", "Nilsson", "Svensson", "Pettersson" };

            for (var i = 0; i < 100; i++)
            {
                school.Classes[i % school.Classes.Count].Students.Add(new Student
                {
                    FirstName = firstNames[i % firstNames.Length],
                    LastName  = lastNames[i % lastNames.Length]
                });
            }
            var spec = entitySpec.Begin()
                       .Add("Name")
                       .Add(entitySpec.Begin("Classes")
                            .Add("Name")
                            .Add(entitySpec.Begin("Students")
                                 .Add("FirstName")
                                 .Add("LastName")));


            const int numberOfSchools = 10000;
            var       tableFactory    = new SqlTableManager(SqlTestHelpers.ConnectionString("SchoolTest"));
            var       export          = new DataExtract <School>(spec, tableFactory);

            SqlTestHelpers.WithNewDb("SchoolTest", conn =>
            {
                var sw = Stopwatch.StartNew();
                export.Run(Enumerable.Range(0, numberOfSchools).Select(_ => school));
                Console.WriteLine(sw.ElapsedMilliseconds.ToString());
                sw.Restart();
                Console.WriteLine(sw.ElapsedMilliseconds.ToString());
                //Assert.AreEqual(numberOfSchools, SqlStuff.SimpleQuery<int>(conn, "SELECT count(*) FROM school"));
                //Assert.AreEqual(numberOfSchools * 6, SqlStuff.SimpleQuery<int>(conn, "SELECT count(*) FROM classes"));
                //Assert.AreEqual(numberOfSchools * 100, SqlStuff.SimpleQuery<int>(conn, "SELECT count(*) FROM students"));
            });

            Console.ReadLine();
        }