Пример #1
0
        protected override Expression VisitConstant(ConstantExpression expression)
        {
            var parentModelVisitor = LinqUtility.FindParentModelVisitor(this.ModelVisitor);

            parentModelVisitor.ParameterNameCounter++;
            string parameterName = "P" + parentModelVisitor.ParameterNameCounter;

            parentModelVisitor.QueryData.BindVars.Add(new QueryParameter()
            {
                Name = parameterName, Value = expression.Value
            });

            ModelVisitor.QueryText.AppendFormat(" @{0} ", parameterName);

            return(expression);
        }
Пример #2
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);
        }
Пример #3
0
        public void VisitGroupByClause(GroupByClause groupByClause, QueryModel queryModel, int index)
        {
            var parentMVisitor = LinqUtility.FindParentModelVisitor(this);

            parentMVisitor.GroupByNameCounter++;
            groupByClause.IntoName          = "C" + parentMVisitor.GroupByNameCounter;
            groupByClause.FuncIntoName      = Db.Setting.Linq.TranslateGroupByIntoName;
            groupByClause.FromParameterName = queryModel.MainFromClause.ItemName;

            QueryText.Append(" collect ");

            if (groupByClause.Selector.NodeType != ExpressionType.New)
            {
                groupByClause.CollectVariableName = "CV" + parentMVisitor.GroupByNameCounter;
                QueryText.AppendFormat(" {0} = ", LinqUtility.ResolvePropertyName(groupByClause.CollectVariableName));
            }

            GetAqlExpression(groupByClause.Selector, queryModel, true);

            QueryText.AppendFormat(" into {0} ", LinqUtility.ResolvePropertyName(groupByClause.TranslateIntoName()));

            groupByClause.Visited = true;
        }