private static ReqlExpr ResolveMemberExpression( ReqlExpr reqlExpr, MemberExpression expression )
 {
     if( expression.Expression.NodeType == ExpressionType.MemberAccess )
         reqlExpr = ResolveMemberExpression( reqlExpr, (MemberExpression)expression.Expression );
     if( expression.Expression.NodeType == ExpressionType.Extension && expression.Expression is SubQueryExpression )
         reqlExpr = ResolveExtensionExpression( reqlExpr, (SubQueryExpression)expression.Expression );
     return reqlExpr[expression.Member.Name];
 }
        private static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate )
        {
            var subQueryExpression = predicate as SubQueryExpression;
            var where = subQueryExpression.QueryModel.BodyClauses[0] as WhereClause;

            var visitor = new ExpressionVisitor( reqlExpr, subQueryExpression.QueryModel.MainFromClause.ItemType );
            visitor.Visit( where.Predicate );
            return visitor.Current;
        }
Exemplo n.º 3
0
 public static ReqlExpr TranslateUnary( ExpressionType type, ReqlExpr term )
 {
     switch( type )
     {
         case ExpressionType.Not:
             return term.Not();
         default:
             throw new NotSupportedException( "Unary term not supported." );
     }
 }
        private static ReqlExpr ResolveExtensionExpression( ReqlExpr reqlExpr, SubQueryExpression expression )
        {
            var subQueryVisitors = new List<ISubQueryVisitor>
            {
                new AnySubQueryVisitor(),
                new AllSubQueryVisitor(),
                new FirstAndLastSubQueryVisitor()
            };

            var subQueryVisitor = subQueryVisitors.FirstOrDefault( x => x.CanVisit( expression.QueryModel ) );

            if( subQueryVisitor == null )
                throw new NotSupportedException( "subqueries not allowed ." );

            return subQueryVisitor.Visit( reqlExpr, expression.QueryModel );
        }
Exemplo n.º 5
0
 public static ReqlExpr TranslateBinary( ExpressionType type, ReqlExpr left, ReqlExpr right )
 {
     switch( type )
     {
         case ExpressionType.Equal:
             return left.Eq( right );
         case ExpressionType.NotEqual:
             return left.Eq( right ).Not();
         case ExpressionType.LessThan:
             return left.Lt( right );
         case ExpressionType.LessThanOrEqual:
             return left.Le( right );
         case ExpressionType.GreaterThan:
             return left.Gt( right );
         case ExpressionType.GreaterThanOrEqual:
             return left.Ge( right );
         case ExpressionType.And:
         case ExpressionType.AndAlso:
             return left.And( right );
         case ExpressionType.Or:
         case ExpressionType.OrElse:
             return left.Or( right );
         case ExpressionType.Not:
             throw new InvalidOperationException( "ExpresionType:Not cannot be called on a binary translation." );
         case ExpressionType.Add:
             return left.Add( right );
         case ExpressionType.Subtract:
             return left.Sub( right );
         case ExpressionType.Multiply:
             return left.Mul( right );
         case ExpressionType.Divide:
             return left.Div( right );
         case ExpressionType.Modulo:
             return left.Mod( right );
         default:
             throw new NotSupportedException( "Binary expression not supported." );
     }
 }
 public ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate )
 {
     return expression.Filter( x => x["reduction"].Contains( reqlExpr => GetWhereReqlAst( reqlExpr, predicate ) ) );
 }
 private static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate )
 {
     var visitor = new ExpressionVisitor( reqlExpr, typeof( bool ) );
     visitor.Visit( predicate );
     return visitor.Current;
 }
Exemplo n.º 8
0
 private ReqlExpr IsForbidden(ReqlExpr x)
 {
     return R.Expr(R.Array(1, 2, 3)).Contains(number => number.Eq(x));
 }
Exemplo n.º 9
0
 private static ReqlExpr GetWhereReqlAst( ReqlExpr reqlExpr, Expression predicate, QueryModel queryModel )
 {
     var visitor = new ExpressionVisitor( reqlExpr, GetResultType( queryModel ) );
     visitor.Visit( predicate );
     return visitor.Current;
 }
Exemplo n.º 10
0
 public ReqlExpr Parse( ReqlExpr expression, QueryModel queryModel, Expression predicate )
 {
     return expression.Filter( reqlExpr => GetWhereReqlAst( reqlExpr, predicate, queryModel ) );
 }
 public ReqlExpr Resolve( ReqlExpr reqlExpr ) => ResolveMemberExpression( reqlExpr, _expression );
Exemplo n.º 12
0
 private ReqlExpr BuildDynamicFilter(ReqlExpr expr, string[] colorSearch)
 {
     var statement = R.Or();
     foreach( var color in colorSearch )
     {
         statement = statement.Or(expr[nameof(Product.ColorCode)].Eq(color));
     }
     return statement;
 }