コード例 #1
0
        /// <summary>
        /// Main entry point for the class. Builds or retrive from cache a SQL query corresponding to given Expressions
        /// </summary>
        /// <param name="expressions"></param>
        /// <param name="queryContext"></param>
        /// <returns></returns>
        public SelectQuery GetSelectQuery(ExpressionChain expressions, QueryContext queryContext)
        {
            SelectQuery query = null;

            if (queryContext.DataContext.QueryCacheEnabled)
            {
                query = GetFromSelectCache(expressions);
            }
            if (query == null)
            {
                Profiler.At("START: GetSelectQuery(), building Expression query");
                var expressionsQuery = BuildExpressionQuery(expressions, queryContext);
                Profiler.At("END: GetSelectQuery(), building Expression query");

                Profiler.At("START: GetSelectQuery(), building Sql query");
                query = BuildSqlQuery(expressionsQuery, queryContext);
                Profiler.At("END: GetSelectQuery(), building Sql query");

                if (queryContext.DataContext.QueryCacheEnabled)
                {
                    SetInSelectCache(expressions, query);
                }
            }
            else if (query.InputParameters.Count > 0)
            {
                Profiler.At("START: GetSelectQuery(), building Expression parameters of cached query");
                var parameters = BuildExpressionParameters(expressions, queryContext);
                query = new SelectQuery(queryContext.DataContext, query.Sql, parameters, query.RowObjectCreator, query.ExecuteMethodName);
                Profiler.At("END: GetSelectQuery(), building Expression parameters of cached query");
            }
            return(query);
        }
コード例 #2
0
        /// <summary>
        /// Main entry point for the class. Builds or retrive from cache a SQL query corresponding to given Expressions
        /// </summary>
        /// <param name="expressions"></param>
        /// <param name="queryContext"></param>
        /// <returns></returns>
        public SelectQuery GetSelectQuery(ExpressionChain expressions, QueryContext queryContext)
        {
            SelectQuery query = null;

            if (queryContext.DataContext.QueryCacheEnabled)
            {
                query = GetFromSelectCache(expressions);
            }
            if (query == null)
            {
                Profiler.At("START: GetSelectQuery(), building Expression query");
                var expressionsQuery = BuildExpressionQuery(expressions, queryContext);
                Profiler.At("END: GetSelectQuery(), building Expression query");

                Profiler.At("START: GetSelectQuery(), building Sql query");
                query = BuildSqlQuery(expressionsQuery, queryContext);
                Profiler.At("END: GetSelectQuery(), building Sql query");

                if (queryContext.DataContext.QueryCacheEnabled)
                {
                    SetInSelectCache(expressions, query);
                }
            }
            return(query);
        }
コード例 #3
0
ファイル: QueryBuilder.cs プロジェクト: Fax/dblinq2007
        public SelectQuery GetSelectQuery(ExpressionChain expressions, QueryContext queryContext)
        {
            Profiler.At("START: GetSelectQuery(), building Expression query");
            var builderContext = BuildExpressionQuery(
                expressions,
                queryContext,
                !queryContext.DataContext.QueryCacheEnabled);

            Profiler.At("END: GetSelectQuery(), building Expression query");

            Profiler.At("START: GetSelectQuery(), building Sql query");
            var sql = SqlBuilder.BuildSelect(builderContext.ExpressionQuery, queryContext);

            Profiler.At("END: GetSelectQuery(), building Sql query");

            // we cache the sql
            var cb = new StringBuilder(sql.ToString());

            foreach (var e in expressions)
            {
                cb.Append(e);
            }

            var cacheKey = cb.ToString();

            // correct, but very time consuming:
            // AND the reader, cause it is possible to have same sql and different reader-parameters
            //= string.Concat(sql,builderContext.ExpressionQuery.Select.Reader);

            if (queryContext.DataContext.QueryCacheEnabled)
            {
                Delegate rowObjectCreator = null;

                if (selectRowCreators.TryGetValue(cacheKey, out rowObjectCreator))
                {
                    builderContext.ExpressionQuery.RowObjectCreator = rowObjectCreator;
                }
            }

            if (builderContext.ExpressionQuery.RowObjectCreator == null)
            {
                // finally, compile our object creation method; this is the Time-Expensive stuff
                CompileRowCreator(builderContext);
                if (queryContext.DataContext.QueryCacheEnabled)
                {
                    selectRowCreators.MergeSafe(cacheKey, builderContext.ExpressionQuery.RowObjectCreator);
                }
            }
            var query = new SelectQuery(
                queryContext.DataContext,
                sql,
                builderContext.ExpressionQuery.Parameters,
                builderContext.ExpressionQuery.RowObjectCreator,
                builderContext.ExpressionQuery.Select.ExecuteMethodName);

            return(query);
        }
コード例 #4
0
        public void TestSetup()
        {
            base.BaseSetUp();

            Profiler.At("START: WriteTest.TestSetup()");

            Northwind db = CreateDB();
            // "[Products]" gets converted to "Products".
            //This is a DbLinq-defined escape sequence, by Pascal.
            //db.ExecuteCommand("DELETE FROM [Products] WHERE [ProductName] like 'temp%'");

            var deleteProducts = db.Products.Where(p => p.ProductName.StartsWith("temp")).ToList();

            db.Products.DeleteAllOnSubmit(deleteProducts);

            var deleteCategories = db.Categories.Where(c => c.CategoryName.StartsWith("temp")).ToList();

            db.Categories.DeleteAllOnSubmit(deleteCategories);

            db.SubmitChanges();

            Profiler.At("END: WriteTest.TestSetup()");
        }
コード例 #5
0
 public DataContext(IDatabaseContext databaseContext, MappingSource mappingSource, IVendor vendor)
 {
     Profiler.At("START DataContext(IDatabaseContext, MappingSource, IVendor)");
     Init(databaseContext, mappingSource, vendor);
     Profiler.At("END DataContext(IDatabaseContext, MappingSource, IVendor)");
 }