示例#1
0
        public void SetUp()
        {
            builder = new QueryBuilder();
            var dir = Directory.GetCurrentDirectory();

            executor = new QueryExecutor(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + dir + @"\App_Data\TestData.mdf;Integrated Security=True;Connect Timeout=30");
        }
示例#2
0
        public void QueryOverModelExecutesFastEnough()
        {
            const int REPETITIONS = 1000;

            AddTestData();
            var count = 0;

            using (var connection = CreateConnection())
            {
                Stopwatch sw = new Stopwatch();
                sw.Start();
                var executor = new QueryExecutor(connection.ConnectionString);
                for (var i = 0; i < REPETITIONS; i++)
                {
                    count = executor.LoadObjects <Role>(@"select * from Role", new Dictionary <string, object>()).ToList().Count;
                }
                sw.Stop();
                Console.WriteLine("ELEMENTS: {0}", count);
                Console.WriteLine("SQL + EXECUTOR: {0}", sw.Elapsed);
                sw.Reset();
                sw.Start();
                for (var i = 0; i < REPETITIONS; i++)
                {
                    count = connection.Query <User>(@"select * from Role").Count();
                }
                sw.Stop();
                Console.WriteLine("ELEMENTS: {0}", count);
                Console.WriteLine("SQL + DAPPER:  {0}", sw.Elapsed);
                sw.Reset();
                sw.Start();
                for (var i = 0; i < REPETITIONS; i++)
                {
                    Expression <Func <IQuery <Role> > > roles = () => from r in builder.Table <Role>() select r;
                    roles.ToString();
                    count = connection.Query <User>(@"select * from Role").Count();
                }
                sw.Stop();
                Console.WriteLine("ELEMENTS: {0}", count);
                Console.WriteLine("CACHED LINQ + DAPPER:  {0}", sw.Elapsed);
                sw.Reset();
                sw.Start();
                for (var i = 0; i < REPETITIONS; i++)
                {
                    count = connection.Query(from r in builder.Table <Role>() select r).Count();
                }
                sw.Stop();
                Console.WriteLine("ELEMENTS: {0}", count);
                Console.WriteLine("LINQ + DAPPER: {0}", sw.Elapsed);
            }
        }