示例#1
0
 protected override Expression VisitSelect(SelectExpression select)
 {
     select = (SelectExpression)base.VisitSelect(select);
     if (select.Skip != null)
     {
         Expression       expression3;
         SelectExpression sel = select.SetSkip(null).SetTake(null);
         if (select.IsDistinct || ((select.GroupBy != null) && (select.GroupBy.Count != 0)))
         {
             sel = sel.AddRedundantSelect(this.language, new TableAlias());
         }
         QueryType columnType = this.language.TypeSystem.GetColumnType(typeof(int));
         sel = sel.AddColumn(new ColumnDeclaration("row__num", new RowNumberExpression(select.OrderBy), columnType)).AddRedundantSelect(this.language, new TableAlias());
         sel = sel.RemoveColumn(sel.Columns.Single <ColumnDeclaration>(c => c.Name == "row__num"));
         TableAlias       alias      = ((SelectExpression)sel.From).Alias;
         ColumnExpression expression = new ColumnExpression(typeof(int), columnType, alias, "row__num");
         if (select.Take != null)
         {
             expression3 = new BetweenExpression(expression, Expression.Add(select.Skip, Expression.Constant(1)), Expression.Add(select.Skip, select.Take));
         }
         else
         {
             expression3 = expression.GreaterThan(select.Skip);
         }
         if (sel.Where != null)
         {
             expression3 = sel.Where.And(expression3);
         }
         select = sel.SetWhere(expression3);
     }
     return(select);
 }
示例#2
0
        public virtual ProjectionExpression AddOuterJoinTest(ProjectionExpression proj)
        {
            QueryType        columnType;
            Expression       outerJoinTest = this.GetOuterJoinTest(proj.Select);
            SelectExpression select        = proj.Select;
            ColumnExpression test          = null;

            foreach (ColumnDeclaration declaration in select.Columns)
            {
                if (outerJoinTest.Equals(declaration.Expression))
                {
                    columnType = this.TypeSystem.GetColumnType(outerJoinTest.Type);
                    test       = new ColumnExpression(outerJoinTest.Type, columnType, select.Alias, declaration.Name);
                    break;
                }
            }
            if (test == null)
            {
                test = outerJoinTest as ColumnExpression;
                string baseName = (test != null) ? test.Name : "Test";
                baseName   = proj.Select.Columns.GetAvailableColumnName(baseName);
                columnType = this.TypeSystem.GetColumnType(outerJoinTest.Type);
                select     = select.AddColumn(new ColumnDeclaration(baseName, outerJoinTest, columnType));
                test       = new ColumnExpression(outerJoinTest.Type, columnType, select.Alias, baseName);
            }
            return(new ProjectionExpression(select, new OuterJoinedExpression(test, proj.Projector), proj.Aggregator));
        }