示例#1
0
        public string Generate()
        {
            StringBuilder sql = new StringBuilder();

            BuildSelectCountClause(sql);

            if (_innerQuery.IsJoin)
            {
                sql.Append(" FROM (");
                _innerQuery.BuildSelectClause(sql);
                _innerQuery.BuildFromClause(sql);
                _innerQuery.BuildJoinClauses(sql);
                _innerQuery.BuildWhereClause(sql);
                _innerQuery.BuildGroupBy(sql);
                sql.Append(") ");

                return(sql.ToString());
            }

            _innerQuery.BuildFromClause(sql);
            _innerQuery.BuildJoinClauses(sql);
            _innerQuery.BuildWhereClause(sql);

            return(sql.ToString());
        }
        private string SimplePaging()
        {
            // Create paged query
            StringBuilder sql = new StringBuilder();

            _innerQuery.BuildSelectClause(sql);
            _innerQuery.BuildFromClause(sql);
            _innerQuery.BuildJoinClauses(sql);
            _innerQuery.BuildWhereClause(sql);
            _innerQuery.BuildOrderClause(sql);
            sql.AppendLine(String.Format(" LIMIT {0},{1}", _skip, _take));

            return(sql.ToString());
        }
        /// <summary>
        /// Generates a query that pages a simple inner query.
        /// </summary>
        /// <returns></returns>
        private string SimplePaging()
        {
            // Create paged query
            StringBuilder sql = new StringBuilder();

            sql.AppendLine("WITH RowNumCTE AS");
            sql.AppendLine("(");
            _innerQuery.BuildSelectClause(sql);
            BuildRowNumberColumn(sql);
            _innerQuery.BuildFromClause(sql);
            _innerQuery.BuildJoinClauses(sql);
            _innerQuery.BuildWhereClause(sql);
            sql.AppendLine(")");
            BuildSimpleOuterSelect(sql);

            return(sql.ToString());
        }
示例#4
0
        /// <summary>
        /// Generates a row count query for a multiple table joined query (groups by the parent entity).
        /// </summary>
        /// <returns></returns>
        private string ComplexRowCount()
        {
            // Create paged query
            StringBuilder sql = new StringBuilder();

            sql.AppendLine("WITH GroupCTE AS (");
            sql.Append("SELECT ").AppendLine(BuildBaseTablePKColumns());
            BuildGroupColumn(sql);
            _innerQuery.BuildFromClause(sql);
            _innerQuery.BuildJoinClauses(sql);
            _innerQuery.BuildWhereClause(sql);
            sql.AppendLine(")");
            BuildSelectCountClause(sql);
            sql.AppendLine("FROM GroupCTE");
            sql.AppendLine("WHERE GroupRow = 1");

            return(sql.ToString());
        }
        public string Generate()
        {
            StringBuilder sql = new StringBuilder();

            BuildSelectCountClause(sql);
            _innerQuery.BuildFromClause(sql);
            _innerQuery.BuildJoinClauses(sql);
            _innerQuery.BuildWhereClause(sql);

            return(sql.ToString());
        }