protected override Expression VisitBinary(BinaryExpression node) { if (_parsePhase.Get() == ParsePhase.Condition) { if (node.NodeType == ExpressionType.AndAlso) { // It's the AND of the WHERE/IF clause Visit(node.Left); // Add the new condition for the right portion _conditions.Add(new BinaryConditionItem()); Visit(node.Right); return(node); } var condition = _conditions.Last(); if (BinaryConditionItem.IsSupported(node.NodeType)) { if (node.NodeType == ExpressionType.Equal && IsBoolMember(node.Left)) { // Handle x.prop == boolValue explicitly FillBooleanCondition((MemberExpression)node.Left, condition); Visit(node.Right); return(node); } if (node.NodeType == ExpressionType.Equal && IsBoolMember(node.Right)) { // Handle boolValue == x.prop explicitly FillBooleanCondition((MemberExpression)node.Right, condition); Visit(node.Left); return(node); } Visit(CqlExpressionVisitor.DropNullableConversion(node.Left)); condition.SetOperator(node.NodeType); Visit(CqlExpressionVisitor.DropNullableConversion(node.Right)); return(node); } if (!CqlExpressionVisitor.CqlUnsupTags.Contains(node.NodeType)) { condition.SetParameter(Expression.Lambda(node).Compile().DynamicInvoke()); return(node); } } else if (_parsePhase.Get() == ParsePhase.SelectBinding) { var column = _pocoData.GetColumnByMemberName(_currentBindingName.Get()); if (column == null) { throw new ArgumentException("Trying to select a column does it excluded in the mappings"); } AddProjection(node, column); _selectFields.Add(column.ColumnName); return(node); } throw new CqlLinqNotSupportedException(node, _parsePhase.Get()); }
protected override Expression VisitUnary(UnaryExpression node) { if (_parsePhase.Get() == ParsePhase.Condition) { var condition = _conditions.Last(); if (node.NodeType == ExpressionType.Not && node.Operand.NodeType == ExpressionType.MemberAccess) { // We are evaluating a boolean expression parameter, the value we are trying to match is false FillBooleanCondition((MemberExpression)node.Operand, condition, false); return(node); } if (BinaryConditionItem.IsSupported(node.NodeType)) { condition.SetOperator(node.NodeType); Visit(CqlExpressionVisitor.DropNullableConversion(node.Operand)); } else if (node.NodeType == ExpressionType.Convert) { Visit(node.Operand); } else { var val = Expression.Lambda(node).Compile().DynamicInvoke(); condition.SetParameter(val); } return(node); } if (_parsePhase.Get() == ParsePhase.SelectBinding) { if (node.NodeType == ExpressionType.Convert && node.Type.Name == "Nullable`1") { // ReSharper disable once AssignNullToNotNullAttribute return(Visit(node.Operand)); } var column = _pocoData.GetColumnByMemberName(_currentBindingName.Get()); if (column != null && column.IsCounter) { var value = Expression.Lambda(node).Compile().DynamicInvoke(); if (!(value is long || value is int)) { throw new ArgumentException("Only Int64 and Int32 values are supported as counter increment of decrement values"); } _projections.Add(Tuple.Create(column, value, ExpressionType.Increment)); _selectFields.Add(column.ColumnName); return(node); } } throw new CqlLinqNotSupportedException(node, _parsePhase.Get()); }