Represents an Select statement and a additional mapping to C# constructs
Inheritance: System.Linq.Expressions.Expression
Exemplo n.º 1
0
        public ProjectionExpression UpdateSelect(ProjectionExpression projection, Expression selectExpression)
        {
            //get the lambda expression of the select method
            var lambda = (LambdaExpression)selectExpression.StripQuotes();

            //if the lambda, is the identity lamda, simply return
            if (lambda.IsIdentityLambda())
                return projection;

            //map the source argument of the lambda expression to the existing projection
            Map.Add(lambda.Parameters[0], projection.Projection);

            //get the new projection
            var newProjection = Visit(lambda.Body);

            //check if projection is actually changed
            if (newProjection == lambda.Body)
                return projection;

            //get used columns
            IEnumerable<SelectorExpression> columns = new ColumnFinder().FindColumns(newProjection);

            SelectStatementExpression select = projection.Select;
            var newSelect = new SelectStatementExpression(typeof(IEnumerable<>).MakeGenericType(newProjection.Type),
                                                          new SelectClauseExpression(columns.ToArray(),
                                                                                     select.SelectClause.Distinct),
                                                          select.TableName,
                                                          select.WhereClause,
                                                          select.OrderBy,
                                                          select.Limit,
                                                          select.AllowFiltering);
            
            return new ProjectionExpression(newSelect, newProjection, projection.Aggregator, false, projection.Consistency, projection.PageSize);
        }
Exemplo n.º 2
0
        public ProjectionExpression BuildWhere(ProjectionExpression projection, Expression whereClause)
        {
            //get the lambda expression of the select method
            var lambda = (LambdaExpression)whereClause.StripQuotes();

            //map the source argument of the lambda expression to the existing projection (the projection is what the where clause queries)
            Map.Add(lambda.Parameters[0], projection.Projection);

            if (projection.Select.WhereClause != null)
                _relations = new HashSet<RelationExpression>(projection.Select.WhereClause);
            else
                _relations = new HashSet<RelationExpression>();

            //get the new projections
            Expression expression = Visit(lambda.Body);

            if (!expression.IsTrue())
                throw new CqlLinqException("Where clause contains unsupported constructs");

            var select = projection.Select;

            var newSelectStmt = new SelectStatementExpression(select.Type,
                                                              select.SelectClause,
                                                              select.TableName,
                                                              _relations.ToArray(),
                                                              select.OrderBy,
                                                              select.Limit,
                                                              select.AllowFiltering);

            return new ProjectionExpression(newSelectStmt, projection.Projection,
                                            projection.Aggregator, projection.CanTrackChanges, projection.Consistency, projection.PageSize);
        }
Exemplo n.º 3
0
        public ProjectionExpression UpdateOrder(ProjectionExpression projection, Expression keySelectExpression,
                                                bool ascending)
        {
            //get the lambda expression of the select method
            var lambda = (LambdaExpression)keySelectExpression.StripQuotes();

            //map the source argument of the lambda expression to the existing projection
            Map.Add(lambda.Parameters[0], projection.Projection);

            //get the new projection
            var key = Visit(lambda.Body);

            //check if we are dealing with a column
            if ((CqlExpressionType)key.NodeType != CqlExpressionType.IdentifierSelector)
                throw new CqlLinqException("Select key in OrderBy does not map to table column");

            //get a reference to the select clause
            SelectStatementExpression select = projection.Select;

            //add the ordering to the list of orderBy clauses
            var ordering = new List<OrderingExpression>(select.OrderBy);
            ordering.Add(new OrderingExpression((SelectorExpression)key,
                                                ascending
                                                    ? CqlExpressionType.OrderAscending
                                                    : CqlExpressionType.OrderDescending));

            var newSelect = new SelectStatementExpression(select.Type,
                                                          select.SelectClause,
                                                          select.TableName,
                                                          select.WhereClause,
                                                          ordering,
                                                          select.Limit,
                                                          select.AllowFiltering);

            return new ProjectionExpression(newSelect, projection.Projection,
                                            projection.Aggregator, projection.CanTrackChanges, projection.Consistency, projection.PageSize);
        }
Exemplo n.º 4
0
 public virtual Expression VisitProjection(ProjectionExpression node)
 {
     return base.VisitExtension(node);
 }