Esempio n. 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 (var 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);
        }
Esempio n. 2
0
        protected internal 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 (var 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);
        }
Esempio n. 3
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 (var i = 0; i < newExpression.Members.Count; i++)
                    {
                        var 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");
                }

                var 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);
        }