Ejemplo n.º 1
0
        public void VisitUpsertClause(UpsertClause upsertClause, QueryModel queryModel)
        {
            QueryText.Append(" upsert ");
            GetAqlExpression(upsertClause.SearchSelector, queryModel);

            QueryText.Append(" insert ");
            GetAqlExpression(upsertClause.InsertSelector, queryModel);

            QueryText.Append(" update ");
            GetAqlExpression(upsertClause.UpdateSelector, queryModel);

            QueryText.AppendFormat(" in {0} ", LinqUtility.ResolveCollectionName(Db, upsertClause.CollectionType));
        }
Ejemplo n.º 2
0
        public void VisitRemoveClause(RemoveClause removeClause, QueryModel queryModel)
        {
            if (removeClause.KeySelector != null)
            {
                QueryText.Append(" remove ");

                GetAqlExpression(removeClause.KeySelector, queryModel);
            }
            else
            {
                QueryText.AppendFormat(" remove {0} ", LinqUtility.ResolvePropertyName(removeClause.ItemName));
            }

            QueryText.AppendFormat(" in {0} ", LinqUtility.ResolveCollectionName(Db, removeClause.CollectionType));
        }
Ejemplo n.º 3
0
        public void VisitInsertClause(InsertClause insertClause, QueryModel queryModel)
        {
            if (insertClause.WithSelector != null)
            {
                QueryText.Append(" insert ");

                GetAqlExpression(insertClause.WithSelector, queryModel);
            }
            else
            {
                QueryText.AppendFormat(" insert {0} ", LinqUtility.ResolvePropertyName(insertClause.ItemName));
            }

            QueryText.AppendFormat(" in {0} ", LinqUtility.ResolveCollectionName(Db, insertClause.CollectionType));
        }
Ejemplo n.º 4
0
        public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
        {
            if (fromClause.FromExpression as SubQueryExpression != null)
            {
                throw new Exception("MainFromClause.FromExpression cant be SubQueryExpression because group by is handle in itself clause");
            }

            string fromName = LinqUtility.ResolveCollectionName(this.Db, fromClause.ItemType);

            //  .Select(g => g.Select(gList => gList.Age)) subquery select, changes the fromName to group name (C1 for example)
            if (fromClause.FromExpression.Type.Name == "IGrouping`2")
            {
                var groupByClause = LinqUtility.PriorGroupBy(ParnetModelVisitor);

                var parentMVisitor = LinqUtility.FindParentModelVisitor(this);
                //parentMVisitor.GroupByNameCounter++;

                fromName = groupByClause[0].TranslateIntoName();

                fromName = LinqUtility.ResolvePropertyName(fromName);
            }

            //  == "IGrouping`2" => .Select(g => g.Select(gList => gList.Age)) subquery select
            if (fromClause.FromExpression.NodeType == ExpressionType.Constant ||
                fromClause.FromExpression.Type.Name == "IGrouping`2")
            {
                if (fromClause.FromExpression.Type.Name == "ArangoQueryable`1" || fromClause.FromExpression.Type.Name == "IGrouping`2")
                {
                    QueryText.AppendFormat(" for {0} in {1} ", LinqUtility.ResolvePropertyName(fromClause.ItemName), fromName);
                }
                else
                {
                    QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName));
                    GetAqlExpression(fromClause.FromExpression, queryModel);
                }
            }
            else
            {
                QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName));
                GetAqlExpression(fromClause.FromExpression, queryModel);
            }

            base.VisitMainFromClause(fromClause, queryModel);
        }
Ejemplo n.º 5
0
        public void VisitUpdateReplaceClause(UpdateReplaceClause updateReplaceClause, QueryModel queryModel)
        {
            if (updateReplaceClause.KeySelector != null)
            {
                QueryText.AppendFormat(" {0} ", updateReplaceClause.Command);

                GetAqlExpression(updateReplaceClause.KeySelector, queryModel);

                QueryText.AppendFormat(" with ");
            }
            else
            {
                QueryText.AppendFormat(" {0} {1} with ", updateReplaceClause.Command, LinqUtility.ResolvePropertyName(updateReplaceClause.ItemName));
            }

            GetAqlExpression(updateReplaceClause.WithSelector, queryModel);

            QueryText.AppendFormat(" in {0} ", LinqUtility.ResolveCollectionName(Db, updateReplaceClause.CollectionType));
        }
Ejemplo n.º 6
0
        public override void VisitAdditionalFromClause(AdditionalFromClause fromClause, QueryModel queryModel, int index)
        {
            var subQuery = fromClause.FromExpression as SubQueryExpression;

            if (subQuery != null)
            {
                this.DontReturn = true;
                GetAqlExpression(subQuery, queryModel, handleJoin: true);
            }
            else if (fromClause.FromExpression.Type.Name == "ArangoQueryable`1")
            {
                string fromName = LinqUtility.ResolveCollectionName(this.Db, fromClause.ItemType);
                QueryText.AppendFormat(" for {0} in {1} ", LinqUtility.ResolvePropertyName(fromClause.ItemName), fromName);
            }
            else
            {
                QueryText.AppendFormat(" for {0} in ", LinqUtility.ResolvePropertyName(fromClause.ItemName));
                GetAqlExpression(fromClause.FromExpression, queryModel);
            }
        }
Ejemplo n.º 7
0
        protected override Expression VisitMethodCall(MethodCallExpression expression)
        {
            if (expression.Method.Name == "As")
            {
                Visit(expression.Arguments[0]);
                return(expression);
            }

            if (expression.Method.Name == "get_Item" && expression.Method.DeclaringType.Name == "IList`1")
            {
                Visit(expression.Object);
                ModelVisitor.QueryText.Append(" [ ");
                Visit(expression.Arguments[0]);
                ModelVisitor.QueryText.Append(" ] ");
                return(expression);
            }

            string methodName;
            var    userFunction = ModelVisitor.Db.SharedSetting.AqlFunctions.FindFunctionAttribute(expression.Method);
            bool   methodExists = userFunction != null;

            if (methodExists)
            {
                methodName = userFunction.Name;
            }
            else
            {
                methodExists = aqlMethods.TryGetValue(expression.Method.Name, out methodName);
            }

            if (!methodExists)
            {
                throw new InvalidOperationException($"Method {expression.Method.Name} is not supported in ArangoLinqProvider");
            }

            string argumentSeprator = null;
            bool   noParenthesis    = methodsWithNoParenthesis.TryGetValue(methodName, out argumentSeprator);

            if (!noParenthesis)
            {
                ModelVisitor.QueryText.AppendFormat(" {0}( ", methodName);
                argumentSeprator = " , ";
            }

            Type[] genericArguments = null;
            if (methodsWithFirstGenericArgument.Contains(methodName))
            {
                genericArguments = expression.Method.GetGenericArguments();
                var collection = LinqUtility.ResolveCollectionName(ModelVisitor.Db, genericArguments[0]);
                ModelVisitor.QueryText.AppendFormat(" {0}{1}", collection, argumentSeprator);
            }

            if (methodsWithSecondGenericArgument.Contains(methodName))
            {
                var collection = LinqUtility.ResolveCollectionName(ModelVisitor.Db, genericArguments[1]);
                ModelVisitor.QueryText.AppendFormat(" {0}{1}", collection, argumentSeprator);
            }

            for (int i = 0; i < expression.Arguments.Count; i++)
            {
                Visit(expression.Arguments[i]);

                if (i != expression.Arguments.Count - 1)
                {
                    ModelVisitor.QueryText.Append(argumentSeprator);
                }
            }

            if (!noParenthesis)
            {
                ModelVisitor.QueryText.Append(" ) ");
            }

            return(expression);
        }