Exemplo n.º 1
0
 protected override Expression VisitMethodCall(MethodCallExpression m)
 {
     if (m.Method.DeclaringType == typeof(Queryable))
     {
         if (m.Method.Name == "Where")
         {
             _sb.Append("SELECT * FROM (");
             Visit(m.Arguments[0]);
             _sb.Append(") WHERE ");
             var lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
             Visit(lambda.Body);
             return(m);
         }
         if (m.Method.Name == "Select")
         {
             var lambda     = (LambdaExpression)StripQuotes(m.Arguments[1]);
             var projection = new ColumnProjector().ProjectColumns(lambda.Body, _row);
             _sb.Append("SELECT ");
             _sb.Append(projection.Columns);
             _sb.Append(" FROM (");
             Visit(m.Arguments[0]);
             _sb.Append(") ");
             _projection = projection;
             return(m);
         }
     }
     throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
 }
        protected override Expression VisitMethodCall(MethodCallExpression m)
        {
            if (m.Method.DeclaringType == typeof(Queryable))
            {
                this.Visit(m.Arguments[0]);
                if (m.Method.Name == "Where")
                {
                    var expression = LeafEvaluator.PartialEval(m.Arguments[1]);
                    AddPrefix("filter");
                    LambdaExpression lambda = (LambdaExpression)StripQuotes(expression);
                    this.Visit(lambda.Body);
                    return(m);
                }
                else if (m.Method.Name == "Take")
                {
                    AddPrefix("top");
                    this.Visit(m.Arguments[1]);
                    return(m);
                }
                else if (m.Method.Name == "Skip")
                {
                    AddPrefix("skip");
                    this.Visit(m.Arguments[1]);
                    return(m);
                }
                else if (m.Method.Name == "OrderBy")
                {
                    AddPrefix("orderby");
                    LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                    this.Visit(lambda.Body);
                    return(m);
                }
                else if (m.Method.Name == "OrderByDescending")
                {
                    AddPrefix("orderby");
                    LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                    this.Visit(lambda.Body);
                    _sb.Append(" desc");
                    return(m);
                }
                else if (m.Method.Name == "Select")
                {
                    LambdaExpression lambda     = (LambdaExpression)StripQuotes(m.Arguments[1]);
                    ColumnProjection projection = new ColumnProjector().ProjectColumns(lambda);
                    AddPrefix("select");
                    _sb.Append(projection.Columns);
                    this._projection = projection;
                    return(m);
                }
            }

            throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
        }
Exemplo n.º 3
0
            protected override Expression VisitMethodCall(MethodCallExpression m)
            {
                if (m.Method.DeclaringType == typeof(Queryable))
                {
                    if (m.Method.Name == "Where")
                    {
                        sb.Append("SELECT * FROM (");
                        this.Visit(m.Arguments[0]);
                        sb.Append(") AS T WHERE ");
                        LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                        this.Visit(lambda.Body);
                        return(m);
                    }
                    else if (m.Method.Name == "FirstOrDefault")
                    {
                        sb.Append("SELECT * FROM (");
                        this.Visit(m.Arguments[0]);
                        sb.Append(") AS T WHERE ");
                        LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);
                        this.Visit(lambda.Body);
                        return(m);
                    }
                    else if (m.Method.Name == "Select")
                    {
                        LambdaExpression lambda = (LambdaExpression)StripQuotes(m.Arguments[1]);

                        ColumnProjection projection = new ColumnVisitor().ProjectColumns(lambda.Body, this.row);

                        sb.Append("SELECT ");

                        sb.Append(projection.Columns);

                        sb.Append(" FROM (");

                        this.Visit(m.Arguments[0]);

                        sb.Append(") AS T ");

                        this.projection = projection;

                        return(m);
                    }
                }
                throw new NotSupportedException(string.Format("The method '{0}' is not supported", m.Method.Name));
            }
Exemplo n.º 4
0
        public static List <ColumnProjection> GetColumnProjections(string entityName)
        {
            var      entity           = MetadataRepository.Entities.Single(e => e.PhysicalName == entityName);
            GridView gridView         = new GridView();
            var      defaultLayoutXml = GetDefaultLayout(entityName);

            gridView.RestoreLayoutFromString(defaultLayoutXml);
            var projections = gridView.Columns.Cast <GridColumn>()
                              .Where(column => !string.IsNullOrEmpty(column.FieldName))
                              .Select(column => new ColumnProjection(column.FieldName, entity)).ToList();

            gridView.Dispose();
            gridView = null;
            ColumnProjection keyColumnProjection = new ColumnProjection(entityName + "Id", entity);

            if (!projections.Contains(keyColumnProjection))
            {
                projections.Add(keyColumnProjection);
            }
            return(projections);
        }