예제 #1
0
        protected override Expression VisitNew(NewExpression expression)
        {
            // Select(g=>g)
            if (expression.Type.Name == "Grouping`2")
            {
                var groupByClause = LinqUtility.PriorGroupBy(ModelVisitor)[0];
                ModelVisitor.QueryText.AppendFormat(" {0} ", LinqUtility.ResolvePropertyName(groupByClause.TranslateIntoName()));
                return(expression);
            }

            if (!TreatNewWithoutBracket)
            {
                ModelVisitor.QueryText.Append(" { ");
            }
            var e = (NewExpression)NamedExpression.CreateNewExpressionWithNamedArguments(ModelVisitor.Db, expression);

            for (int i = 0; i < e.Arguments.Count; i++)
            {
                Visit(e.Arguments[i]);
                if (i != e.Arguments.Count - 1)
                {
                    ModelVisitor.QueryText.Append(" , ");
                }
            }
            if (!TreatNewWithoutBracket)
            {
                ModelVisitor.QueryText.Append(" } ");
            }

            return(e);
        }
예제 #2
0
        protected override Expression VisitMember(MemberExpression expression)
        {
            var member = expression.Expression as MemberExpression;

            if ((member != null && member.Expression.Type.Name == "IGrouping`2"))
            {
                ModelVisitor.QueryText.AppendFormat(" {0} ", LinqUtility.ResolvePropertyName(expression.Member.Name));
            }
            // Select(g=>g.Key)
            else if (expression.Expression.Type.Name == "IGrouping`2")
            {
                var groupByClause = LinqUtility.PriorGroupBy(ModelVisitor)[0];

                var newExpression = groupByClause.Selector as NewExpression;
                if (newExpression != null)
                {
                    ModelVisitor.QueryText.Append(" { ");
                    for (int i = 0; i < newExpression.Members.Count; i++)
                    {
                        string memberName = newExpression.Members[i].Name;
                        ModelVisitor.QueryText.AppendFormat(" {0} : {1} ",
                                                            LinqUtility.ResolvePropertyName(memberName),
                                                            LinqUtility.ResolvePropertyName(memberName));

                        if (i != newExpression.Members.Count - 1)
                        {
                            ModelVisitor.QueryText.Append(" , ");
                        }
                    }
                    ModelVisitor.QueryText.Append(" } ");
                }

                if (groupByClause.Selector.NodeType != ExpressionType.New)
                {
                    ModelVisitor.QueryText.AppendFormat(" {0} ", LinqUtility.ResolvePropertyName(groupByClause.CollectVariableName));
                }
            }
            else if (expression.Expression.Type.Name == "TraversalData`2" ||
                     expression.Expression.Type.Name == "ShortestPathData`2")
            {
                var parameterExpression = expression.Expression as ParameterExpression;
                if (parameterExpression == null)
                {
                    throw new InvalidOperationException("[TraversalData`2|ShortestPathData`2] VisitMember, expected a ParameterExpression");
                }

                string prefix = LinqUtility.MemberNameFromMap(parameterExpression.Name, "graph", ModelVisitor);

                ModelVisitor.QueryText.AppendFormat(LinqUtility.ResolvePropertyName($"{prefix}_{expression.Member.Name}"));
            }
            else
            {
                Visit(expression.Expression);
                ModelVisitor.QueryText.AppendFormat(".{0} ", LinqUtility.ResolveMemberName(ModelVisitor.Db, expression.Member));
            }

            return(expression);
        }
예제 #3
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);
        }
예제 #4
0
        protected override Expression VisitQuerySourceReference(QuerySourceReferenceExpression expression)
        {
            ModelVisitor.QueryText.AppendFormat(" {0}", LinqUtility.ResolvePropertyName(expression.ReferencedQuerySource.ItemName));

            var mainFromClause = expression.ReferencedQuerySource as MainFromClause;

            //  .Select(g => g.Select(gList => gList.Age)) subquery select, handle prior groupby source parameter names
            if (mainFromClause != null && mainFromClause.FromExpression.Type.Name == "IGrouping`2")
            {
                var groupByClauses = LinqUtility.PriorGroupBy(ModelVisitor);

                for (int i = 0; i < groupByClauses.Count; i++)
                {
                    ModelVisitor.QueryText.AppendFormat("{0}{1}{2}"
                                                        , i == 0 ? "." : ""
                                                        , LinqUtility.ResolvePropertyName(groupByClauses[i].FromParameterName)
                                                        , i != groupByClauses.Count - 1 ? "." : "");
                }
            }

            return(expression);
        }