Exemple #1
0
        protected virtual ReadOnlyCollection <ColumnDeclaration> VisitColumnDeclarations(ReadOnlyCollection <ColumnDeclaration> columns)
        {
            List <ColumnDeclaration> list = null;
            int count = 0;
            int num2  = columns.Count;

            while (count < num2)
            {
                ColumnDeclaration declaration = columns[count];
                Expression        expression  = this.Visit(declaration.Expression);
                if ((list == null) && (expression != declaration.Expression))
                {
                    list = columns.Take <ColumnDeclaration>(count).ToList <ColumnDeclaration>();
                }
                if (list != null)
                {
                    list.Add(new ColumnDeclaration(declaration.Name, expression, declaration.QueryType));
                }
                count++;
            }
            if (list != null)
            {
                return(list.AsReadOnly());
            }
            return(columns);
        }
        public static SelectExpression RemoveColumn(this SelectExpression select, ColumnDeclaration column)
        {
            List <ColumnDeclaration> columns = new List <ColumnDeclaration>(select.Columns);

            columns.Remove(column);
            return(select.SetColumns(columns));
        }
 protected virtual void WriteColumns(ReadOnlyCollection <ColumnDeclaration> columns)
 {
     if (columns.Count > 0)
     {
         int num   = 0;
         int count = columns.Count;
         while (num < count)
         {
             ColumnDeclaration declaration = columns[num];
             if (num > 0)
             {
                 this.Write(", ");
             }
             ColumnExpression expression = this.VisitValue(declaration.Expression) as ColumnExpression;
             if (!(string.IsNullOrEmpty(declaration.Name) || ((expression != null) && !(expression.Name != declaration.Name))))
             {
                 this.Write(" ");
                 this.WriteAsColumnName(declaration.Name);
             }
             num++;
         }
     }
     else
     {
         this.Write("NULL ");
         if (this.isNested)
         {
             this.WriteAsColumnName("tmp");
             this.Write(" ");
         }
     }
 }
Exemple #4
0
        protected override Expression VisitSelect(SelectExpression select)
        {
            ReadOnlyCollection <ColumnDeclaration> columns = select.Columns;
            bool retainAllColumns = this.retainAllColumns;

            this.retainAllColumns = false;
            List <ColumnDeclaration> list = null;
            int num   = 0;
            int count = select.Columns.Count;

            while (num < count)
            {
                ColumnDeclaration item = select.Columns[num];
                if ((retainAllColumns || select.IsDistinct) || this.IsColumnUsed(select.Alias, item.Name))
                {
                    Expression expression = this.Visit(item.Expression);
                    if (expression != item.Expression)
                    {
                        item = new ColumnDeclaration(item.Name, expression, item.QueryType);
                    }
                }
                else
                {
                    item = null;
                }
                if ((item != select.Columns[num]) && (list == null))
                {
                    list = new List <ColumnDeclaration>();
                    for (int i = 0; i < num; i++)
                    {
                        list.Add(select.Columns[i]);
                    }
                }
                if ((item != null) && (list != null))
                {
                    list.Add(item);
                }
                num++;
            }
            if (list != null)
            {
                columns = list.AsReadOnly();
            }
            Expression take = this.Visit(select.Take);
            Expression skip = this.Visit(select.Skip);
            ReadOnlyCollection <Expression>      groupBy = this.VisitExpressionList(select.GroupBy);
            ReadOnlyCollection <OrderExpression> orderBy = this.VisitOrderBy(select.OrderBy);

            Expression where = this.Visit(select.Where);
            Expression from = this.Visit(select.From);

            this.ClearColumnsUsed(select.Alias);
            if (((((columns != select.Columns) || (take != select.Take)) || ((skip != select.Skip) || (orderBy != select.OrderBy))) || ((groupBy != select.GroupBy) || (where != select.Where))) || (from != select.From))
            {
                select = new SelectExpression(select.Alias, columns, from, where, orderBy, groupBy, select.IsDistinct, skip, take, select.IsReverse);
            }
            this.retainAllColumns = retainAllColumns;
            return(select);
        }
        public static SelectExpression AddColumn(this SelectExpression select, ColumnDeclaration column)
        {
            List <ColumnDeclaration> columns = new List <ColumnDeclaration>(select.Columns)
            {
                column
            };

            return(select.SetColumns(columns));
        }
Exemple #6
0
        protected override Expression VisitSelect(SelectExpression selectExpression)
        {
            selectExpression = (SelectExpression)base.VisitSelect(selectExpression);
            List <ColumnDeclaration> list = (from c in selectExpression.Columns
                                             orderby c.Name
                                             select c).ToList <ColumnDeclaration>();
            BitArray array = new BitArray(selectExpression.Columns.Count);
            bool     flag  = false;
            int      index = 0;
            int      count = list.Count;

            while (index < (count - 1))
            {
                ColumnDeclaration declaration = list[index];
                ColumnExpression  expression  = declaration.Expression as ColumnExpression;
                QueryType         queryType   = (expression != null) ? expression.QueryType : declaration.QueryType;
                ColumnExpression  expression2 = new ColumnExpression(declaration.Expression.Type, queryType, selectExpression.Alias, declaration.Name);
                for (int i = index + 1; i < count; i++)
                {
                    if (!array.Get(i))
                    {
                        ColumnDeclaration declaration2 = list[i];
                        if (this.SameExpression(declaration.Expression, declaration2.Expression))
                        {
                            ColumnExpression key = new ColumnExpression(declaration2.Expression.Type, queryType, selectExpression.Alias, declaration2.Name);
                            this.map.Add(key, expression2);
                            array.Set(i, true);
                            flag = true;
                        }
                    }
                }
                index++;
            }
            if (flag)
            {
                List <ColumnDeclaration> columns = new List <ColumnDeclaration>();
                index = 0;
                count = list.Count;
                while (index < count)
                {
                    if (!array.Get(index))
                    {
                        columns.Add(list[index]);
                    }
                    index++;
                }
                selectExpression = selectExpression.SetColumns(columns);
            }
            return(selectExpression);
        }
            private static bool IsColumnProjection(SelectExpression select)
            {
                int num   = 0;
                int count = select.Columns.Count;

                while (num < count)
                {
                    ColumnDeclaration declaration = select.Columns[num];
                    if ((declaration.Expression.NodeType != ((ExpressionType)0x3ea)) && (declaration.Expression.NodeType != ExpressionType.Constant))
                    {
                        return(false);
                    }
                    num++;
                }
                return(true);
            }
Exemple #8
0
 protected override Expression VisitSelect(SelectExpression select)
 {
     select = (SelectExpression)base.VisitSelect(select);
     if (this.lookup.Contains(select.Alias))
     {
         List <ColumnDeclaration> columns = new List <ColumnDeclaration>(select.Columns);
         foreach (AggregateSubqueryExpression expression in this.lookup[select.Alias])
         {
             string            name       = "agg" + columns.Count;
             QueryType         columnType = this.language.TypeSystem.GetColumnType(expression.Type);
             ColumnDeclaration item       = new ColumnDeclaration(name, expression.AggregateInGroupSelect, columnType);
             this.map.Add(expression, new ColumnExpression(expression.Type, columnType, expression.GroupByAlias, name));
             columns.Add(item);
         }
         return(new SelectExpression(select.Alias, columns, select.From, select.Where, select.OrderBy, select.GroupBy, select.IsDistinct, select.Skip, select.Take, select.IsReverse));
     }
     return(select);
 }
        private Expression MakeSubquery(Expression expression)
        {
            TableAlias               alias   = new TableAlias();
            HashSet <TableAlias>     set     = DeclaredAliasGatherer.Gather(expression);
            List <ColumnDeclaration> columns = new List <ColumnDeclaration>();

            foreach (TableAlias alias2 in set)
            {
                foreach (ColumnExpression expression2 in this.columns[alias2])
                {
                    ColumnDeclaration item = new ColumnDeclaration(columns.GetAvailableColumnName(expression2.Name), expression2, expression2.QueryType);
                    columns.Add(item);
                    ColumnExpression expression3 = new ColumnExpression(expression2.Type, expression2.QueryType, alias, expression2.Name);
                    this.map.Add(expression2, expression3);
                }
            }
            return(new SelectExpression(alias, columns, expression, null));
        }
 private void GetColumns(MappingEntity entity, Dictionary <string, TableAlias> aliases, List <ColumnDeclaration> columns)
 {
     foreach (MemberInfo info in this.mapping.GetMappedMembers(entity))
     {
         if (!this.mapping.IsAssociationRelationship(entity, info))
         {
             if (this.mapping.IsNestedEntity(entity, info))
             {
                 this.GetColumns(this.mapping.GetRelatedEntity(entity, info), aliases, columns);
             }
             else if (this.mapping.IsColumn(entity, info))
             {
                 TableAlias alias;
                 string     columnName = this.mapping.GetColumnName(entity, info);
                 string     key        = this.mapping.GetAlias(entity, info);
                 aliases.TryGetValue(key, out alias);
                 QueryType         columnType = this.GetColumnType(entity, info);
                 ColumnExpression  expression = new ColumnExpression(King.Framework.Linq.TypeHelper.GetMemberType(info), columnType, alias, columnName);
                 ColumnDeclaration item       = new ColumnDeclaration(columnName, expression, columnType);
                 columns.Add(item);
             }
         }
     }
 }
 protected virtual bool CompareColumnDeclaration(ColumnDeclaration a, ColumnDeclaration b)
 {
     return((a.Name == b.Name) && this.Compare(a.Expression, b.Expression));
 }