コード例 #1
0
            protected override Expression VisitSubQuery(SubQueryExpression expression)
            {
                var queryType = expression.QueryModel.MainFromClause.ItemType;

                // Simple types
                if (TypeMappings.HasTypeMapping(queryType))
                {
                    var contains = expression.QueryModel.ResultOperators.OfType <ContainsResultOperator>().FirstOrDefault();
                    if (contains != null)
                    {
                        var @where = ContainmentWhereFragment.SimpleArrayContains(_parent._serializer, expression.QueryModel.MainFromClause.FromExpression, contains.Item.Value());
                        _register.Peek()(@where);

                        return(null);
                    }
                }

                if (expression.QueryModel.ResultOperators.Any(x => x is AnyResultOperator))
                {
                    var @where = new CollectionAnyContainmentWhereFragment(_parent._serializer, expression);

                    _register.Peek()(@where);

                    return(null);
                }


                return(base.VisitSubQuery(expression));
            }
コード例 #2
0
        public void Parse()
        {
            var invalidOperators = _query.ResultOperators.Where(x => !ValidOperators.Contains(x.GetType()))
                                   .ToArray();

            if (invalidOperators.Any())
            {
                var names = invalidOperators.Select(x => x.GetType().Name).Join(", ");
                throw new NotSupportedException($"Marten does not yet support {names} operators in child collection queries");
            }

            var members     = FindMembers.Determine(_query.MainFromClause.FromExpression);
            var queryType   = _query.SourceType();
            var isPrimitive = TypeMappings.HasTypeMapping(queryType);



            Visit(_expression);

            // Simple types

            if (isPrimitive)
            {
                var contains = _query.ResultOperators.OfType <ContainsResultOperator>().FirstOrDefault();
                if (contains != null)
                {
                    var @where = ContainmentWhereFragment.SimpleArrayContains(members, _serializer, _query.MainFromClause.FromExpression, contains.Item.Value());
                    _registerFilter(@where);

                    return;
                }
            }

            if (_query.ResultOperators.Any(x => x is AnyResultOperator))
            {
                // Any() without predicate
                if (!_query.BodyClauses.Any())
                {
                    var @where_any_nopredicate = new CollectionAnyNoPredicateWhereFragment(members, _expression);

                    _registerFilter(@where_any_nopredicate);

                    return;
                }

                var @where = new CollectionAnyContainmentWhereFragment(members, _serializer, _expression);
                _registerFilter(@where);
            }
        }
コード例 #3
0
 private static void gatherSearch(BinaryExpression x, Dictionary<string, object> search, ISerializer serializer)
 {
     if (x.NodeType == ExpressionType.AndAlso)
     {
         if (x.Left is BinaryExpression) gatherSearch(x.Left.As<BinaryExpression>(), search, serializer);
         if (x.Right is BinaryExpression) gatherSearch(x.Right.As<BinaryExpression>(), search, serializer);
     }
     else if (x.NodeType == ExpressionType.Equal)
     {
         ContainmentWhereFragment.CreateDictionaryForSearch(x, search, serializer);
     }
     else
     {
         throw new NotSupportedException();
     }
 }
コード例 #4
0
        private IWhereFragment GetMethodCall(IDocumentMapping mapping, MethodCallExpression expression)
        {
            // TODO -- generalize this mess
            if (expression.Method.Name == CONTAINS)
            {
                var @object = expression.Object;

                if (@object.Type == typeof(string))
                {
                    var locator = JsonLocator(mapping, @object);
                    var value   = Value(expression.Arguments.Single()).As <string>();
                    return(new WhereFragment("{0} like ?".ToFormat(locator), "%" + value + "%"));
                }

                if (@object.Type.IsGenericEnumerable())
                {
                    var value = Value(expression.Arguments.Single());
                    return(ContainmentWhereFragment.SimpleArrayContains(_serializer, @object,
                                                                        value));
                }
            }

            if (expression.Method.Name == STARTS_WITH)
            {
                var @object = expression.Object;
                if (@object.Type == typeof(string))
                {
                    var locator = JsonLocator(mapping, @object);
                    var value   = Value(expression.Arguments.Single()).As <string>();
                    return(new WhereFragment("{0} like ?".ToFormat(locator), value + "%"));
                }
            }

            if (expression.Method.Name == ENDS_WITH)
            {
                var @object = expression.Object;
                if (@object.Type == typeof(string))
                {
                    var locator = JsonLocator(mapping, @object);
                    var value   = Value(expression.Arguments.Single()).As <string>();
                    return(new WhereFragment("{0} like ?".ToFormat(locator), "%" + value));
                }
            }

            throw new NotImplementedException();
        }
コード例 #5
0
        private IWhereFragment GetWhereFragment(IDocumentMapping mapping, SubQueryExpression expression)
        {
            var queryType = expression.QueryModel.MainFromClause.ItemType;

            if (TypeMappings.HasTypeMapping(queryType))
            {
                var contains = expression.QueryModel.ResultOperators.OfType <ContainsResultOperator>().FirstOrDefault();
                if (contains != null)
                {
                    return(ContainmentWhereFragment.SimpleArrayContains(_serializer, expression.QueryModel.MainFromClause.FromExpression, Value(contains.Item)));
                }
            }

            if (expression.QueryModel.ResultOperators.Any(x => x is AnyResultOperator))
            {
                return(new CollectionAnyContainmentWhereFragment(_serializer, expression));
            }

            throw new NotImplementedException();
        }