private static void ExecuteQueryLoop(AWEntities oContext, AWL2SDataContext dContext, List <decimal> resultList, QueryType qType, int LoopCount)
        {
            var compQuery = CompiledQuery.Compile <AWEntities, IQueryable <AWCustomer> >
                                ((AWEntities ctx ) =>
                                from c in ctx.AWCustomers select c);


            for (int j = 0; j < LoopCount; j++)
            {
                var sw2 = new System.Diagnostics.Stopwatch();
                sw2.Start();
                //------------using compiled query
                // var customers = compQuery.Invoke(context);

                //iterating is about the same time as tolist
                switch (qType)
                {
                case QueryType.L2E:
                    // oContext = new AWEntities();
                    oContext.AWCustomers.MergeOption = MergeOption.OverwriteChanges;
                    var customers = (from c in oContext.AWCustomers select c).ToList();
                    break;

                case QueryType.EntityObject:
                    //  oContext = new AWEntities();
                    oContext.AWCustomers.MergeOption = MergeOption.OverwriteChanges;
                    var oqCusts = oContext.CreateQuery <AWCustomer>("AWCustomers").ToList();
                    break;

                case QueryType.L2S:
                    var l2SCusts = (from c in dContext.L2SCustomers select c).ToList();
                    break;

                case QueryType.CompiledL2E:
                    var compCusts = compQuery.Invoke(oContext).ToList();

                    break;

                case QueryType.DataReader:
                    break;

                default:
                    throw new ArgumentOutOfRangeException("qType");
                }
                sw2.Stop();
                resultList.Add(sw2.ElapsedMilliseconds);
            }
        }
        private static string LinqToSqlTest()
        {
            //var compQuery = CompiledQuery.Compile<AWEntities,
            //  IQueryable<Customer>>((AWEntities ctx) =>
            //                        from cust in ctx.Customers select cust);


            var     resultList  = new List <decimal>();
            decimal testresults = 0;
            var     sw          = new System.Diagnostics.Stopwatch();
            var     sw2         = new System.Diagnostics.Stopwatch();

            for (int i = 0; i < 2; i++)
            {
                //sw.Reset();
                //sw.Start();

                resultList.Clear();
                var context = new AWL2SDataContext(); //<--been moving this in and out of the next for loop
                for (int j = 0; j < 100; j++)
                {
                    sw2.Reset();
                    sw2.Start();


                    //------------using compiled query
                    // var customers = compQuery.Invoke(context);

                    //iterating is about the same time as tolist
                    var customers = (from c in context.L2SCustomers select c).ToList();
                    sw2.Stop();
                    resultList.Add(sw2.ElapsedMilliseconds);
                }

                //sw.Stop();
                //testresults = sw.ElapsedMilliseconds;
            }

            Console.WriteLine("l2s query 1:{0}", resultList[0]);
            Console.WriteLine("l2s query 2:{0}", resultList[1]);
            Console.WriteLine("l2s query 3:{0}", resultList[2]);

            return(String.Format("LINQ to SQL: {0}ms", testresults));
        }
Exemplo n.º 3
0
        private static decimal LINQtoSQLUpdateTest()
        {
            List <decimal> testresults = new List <decimal>();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            var AWL2SContext = new AWL2SDataContext();

            for (int j = 0; j < iInnerloop; j++)
            {
                var customers = from c in AWL2SContext.L2SCustomers select c;
                foreach (L2SCustomer cust in customers)
                {
                    L2SCustomer o = cust;
                    o.ModifiedDate = o.ModifiedDate.AddDays(1);
                }
                for (int iAdd = 0; iAdd < 10; iAdd++)
                {
                    L2SCustomer cust = new L2SCustomer();
                    cust.NameStyle    = true;
                    cust.FirstName    = "new";
                    cust.LastName     = "cust";
                    cust.PasswordHash = "pw";
                    cust.PasswordSalt = "salt";
                    cust.rowguid      = Guid.NewGuid();
                    cust.ModifiedDate = DateTime.Now;

                    AWL2SContext.L2SCustomers.InsertOnSubmit(cust);
                }

                sw.Reset();
                sw.Start();
                AWL2SContext.SubmitChanges();
                sw.Stop();
                testresults.Add((decimal)sw.ElapsedMilliseconds);
                clearnewcusts(connectionString);
            }

            // figure out how long this took
            //toss first result, calc average of rest
            clearnewcusts(connectionString);
            testresults.Remove(0);
            return(testresults.Average());
        }