Exemplo n.º 1
0
        public void ConfigureCommand(NpgsqlCommand command, int limit)
        {
            var    isComplexSubQuery = _subQuery != null && _subQuery.IsComplex(_joins);
            string sql = "";

            if (isComplexSubQuery)
            {
                if (_subQuery.HasSelectTransform())
                {
                    sql = $"select {_subQuery.RawChildElementField()} from {_mapping.Table.QualifiedName} as d";
                }
                else
                {
                    sql = _innerSelector.ToSelectClause(_mapping);
                }
            }
            else
            {
                sql = Selector.ToSelectClause(_mapping);
            }

            sql = AppendWhere(command, sql);

            var orderBy = determineOrderClause();

            if (orderBy.IsNotEmpty())
            {
                sql += orderBy;
            }

            if (isComplexSubQuery)
            {
                sql = _subQuery.ConfigureCommand(_joins, Selector, command, sql, limit);
            }
            else
            {
                sql = Model.ApplySkip(command, sql);
                sql = Model.ApplyTake(command, limit, sql);
            }

            command.AppendQuery(sql);
        }
Exemplo n.º 2
0
        public void ConfigureCommand(CommandBuilder sql, int limit)
        {
            var isComplexSubQuery = _subQuery != null && _subQuery.IsComplex(_joins);

            // TODO -- lift a new ISelectClause w/ a WriteSelectClause() method
            if (isComplexSubQuery)
            {
                if (_subQuery.HasSelectTransform())
                {
                    sql.Append("select ");
                    sql.Append(_subQuery.RawChildElementField());
                    sql.Append(" from ");
                    sql.Append(_mapping.Table.QualifiedName);
                    sql.Append(" as d");
                }
                else
                {
                    _innerSelector.WriteSelectClause(sql, _mapping);
                }
            }
            else
            {
                Selector.WriteSelectClause(sql, _mapping);
            }

            AppendWhere(sql);

            writeOrderClause(sql);

            if (isComplexSubQuery)
            {
                _subQuery.ConfigureCommand(_joins, Selector, sql, limit);
            }
            else
            {
                Model.ApplySkip(sql);
                Model.ApplyTake(limit, sql);
            }
        }