A CQL Relation (a single comparison statement in a where-clause)
Inheritance: System.Linq.Expressions.Expression
 /// <summary>
 ///   Visits the relation in a where clause.
 /// </summary>
 /// <param name="node"> The node. </param>
 /// <returns> </returns>
 public virtual Expression VisitRelation(RelationExpression node)
 {
     return base.VisitExtension(node);
 }
Esempio n. 2
0
        public override Expression VisitRelation(RelationExpression relation)
        {
            base.VisitRelation(relation);

            var builder = new StringBuilder();
            builder.Append(_translations[relation.Selector]);

            switch ((CqlExpressionType)relation.NodeType)
            {
                case CqlExpressionType.Equal:
                    builder.Append("=");
                    builder.Append(_translations[relation.Term]);
                    break;
                case CqlExpressionType.LargerEqualThan:
                    builder.Append(">=");
                    builder.Append(_translations[relation.Term]);
                    break;
                case CqlExpressionType.LargerThan:
                    builder.Append(">");
                    builder.Append(_translations[relation.Term]);
                    break;
                case CqlExpressionType.SmallerEqualThan:
                    builder.Append("<=");
                    builder.Append(_translations[relation.Term]);
                    break;
                case CqlExpressionType.SmallerThan:
                    builder.Append("<");
                    builder.Append(_translations[relation.Term]);
                    break;
                case CqlExpressionType.In:
                    builder.Append(" IN ");

                    if(((CqlExpressionType)relation.Term.NodeType == CqlExpressionType.Variable))
                    {
                        builder.Append(_translations[relation.Term]);
                    }
                    else
                    {
                        builder.Append("(");
                        var elements = relation.Term.Terms.Select(term => _translations[term]);
                        builder.Append(string.Join(",", elements));
                        builder.Append(")");
                    }

                    break;
                default:
                    throw new CqlLinqException("Unexpected relation encountered in where: " +
                                               relation.NodeType.ToString());
            }

            _translations[relation] = builder.ToString();

            return relation;
        }
        protected override Expression VisitChildren(ExpressionVisitor visitor)
        {
            bool changed = false;

            var selectClause = (SelectClauseExpression) visitor.Visit(_selectClause);
            changed |= selectClause != _selectClause;

            int count = _whereClause.Count;
            var wheres = new RelationExpression[count];
            for (int i = 0; i < count; i++)
            {
                wheres[i] = (RelationExpression) visitor.Visit(_whereClause[i]);
                changed |= wheres[i] != _whereClause[i];
            }

            count = _orderBy.Count;
            var order = new OrderingExpression[count];
            for (int i = 0; i < count; i++)
            {
                order[i] = (OrderingExpression) visitor.Visit(_orderBy[i]);
                changed |= order[i] != _orderBy[i];
            }

            return changed
                       ? new SelectStatementExpression(_type, selectClause, _tableName, wheres, order, _limit,
                                                       _allowFiltering)
                       : this;
        }