Exemple #1
0
        public override void Handle(BinaryExpression expression, VisitorContext context)
        {
            string @operator = null;

            switch (expression.NodeType)
            {
            case ExpressionType.LessThan:
                @operator = "$lt"; break;

            case ExpressionType.LessThanOrEqual:
                @operator = "$lte"; break;

            case ExpressionType.GreaterThan:
                @operator = "$gt"; break;

            case ExpressionType.GreaterThanOrEqual:
                @operator = "$gte"; break;
            }

            var nameValue = GetNameValue(expression);
            //var name = GetMemberName(nameValue.Member, context);

            var compareObject = new QueryObject {
                { @operator, nameValue.Constant.Value }
            };
            var result = CreateQuery(nameValue.Member, compareObject, context);

            context.SetResult(result);
        }
Exemple #2
0
        public override void Handle(UnaryExpression expression, VisitorContext context)
        {
            context.Visit(expression.Operand);
            var val = context.GetResult();

            var result = new QueryObject();

            result.Add("$not", val);

            context.SetResult(result);
        }
        public override void Handle(MethodCallExpression expression, VisitorContext context)
        {
            context.Visit(expression.Arguments[1]);
            var matchCriteria = context.GetResult();

            var regex = new QueryObject {
                { "$elemMatch", matchCriteria }
            };
            var query = CreateQuery(expression.Arguments[0], regex, context);

            context.SetResult(query);
        }
Exemple #4
0
        public override void Handle(MethodCallExpression expression, VisitorContext context)
        {
            var list      = (IEnumerable)((ConstantExpression)(expression.Arguments[0])).Value;
            var binaryExp = (BinaryExpression)((LambdaExpression)expression.Arguments[1]).Body;
            var property  = binaryExp.Right as MemberExpression ?? (MemberExpression)binaryExp.Left;

            var inQuery = new QueryObject {
                { "$in", list }
            };
            var query = CreateQuery(property, inQuery, context);

            context.SetResult(query);
        }
Exemple #5
0
        public override void Handle(BinaryExpression expression, VisitorContext context)
        {
            var nameValue = GetNameValue(expression);
            var @operator = expression.NodeType == ExpressionType.Equal
                ? "$eq"
                : "$ne";

            var equal = new QueryObject {
                { @operator, nameValue.Constant.Value }
            };
            var result = CreateQuery(nameValue.Member, equal, context);

            context.SetResult(result);
        }
        public override void Handle(UnaryExpression expression, VisitorContext context)
        {
            var memberExpression = (MemberExpression)((LambdaExpression)expression.Operand).Body;

            var name = memberExpression.Member.Name;

            var equal = new QueryObject {
                { "$eq", true }
            };
            var result = new QueryObject {
                { name, equal }
            };

            context.SetResult(result);
        }
Exemple #7
0
        public override void Handle(MethodCallExpression expression, VisitorContext context)
        {
            var cValue = expression.Arguments[0] as ConstantExpression;

            if (cValue == null)
            {
                throw new NotSupportedException("requires a parameter");
            }


            //var query = new QueryObject { { $"{name}.{cValue.Value.ToString()}", null } };
            var query = CreateQuery(expression, null, context);

            context.SetResult(query);
        }
Exemple #8
0
        public override void Handle(MethodCallExpression expression, VisitorContext context)
        {
            var cValue = expression.Arguments[0] as ConstantExpression;

            if (cValue == null)
            {
                throw new NotSupportedException("requires a parameter");
            }

            //var name = GetMemberName((MemberExpression)expression.Object, context);

            var regex = new QueryObject {
                { "$regex", cValue.Value }
            };
            var query = CreateQuery(expression.Object, regex, context);

            context.SetResult(query);
        }
Exemple #9
0
        public override void Handle(MethodCallExpression expression, VisitorContext context)
        {
            var cValue = expression.Arguments[0] as ConstantExpression;

            if (cValue == null)
            {
                throw new NotSupportedException("requires a parameter");
            }

            //var name = GetMemberName((MemberExpression)expression.Object, context);

            var exists = new QueryObject {
                { "$exists", true }
            };
            //var query = new QueryObject { { $"{name}.{cValue.Value.ToString()}", exists } };
            var query = CreateQuery(expression, exists, context);

            context.SetResult(query);
        }
Exemple #10
0
        public override void Handle(BinaryExpression expression, VisitorContext context)
        {
            var isAnd = expression.NodeType == ExpressionType.AndAlso ||
                        expression.NodeType == ExpressionType.And;

            context.Visit(expression.Left);
            context.Visit(expression.Right);

            var right = context.GetResult();
            var left  = context.GetResult();

            var @operator = isAnd
                ? "$and"
                : "$or";

            var query = new QueryObject {
                { @operator, new List <IDictionary <string, object> > {
                      left, right
                  } }
            };

            context.SetResult(query);
        }