Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        protected override Expression VisitParameter(ParameterExpression expression)
        {
            string name = expression.Name;

            if (expression.Type.Name == "TraversalData`2")
            {
                string prefix = LinqUtility.MemberNameFromMap(name, "graph", ModelVisitor);

                ModelVisitor.QueryText.AppendFormat(" {{ {0} : {1}, {2} : {3}, {4} : {5} }} ",
                                                    LinqUtility.ResolvePropertyName($"vertex"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                                    LinqUtility.ResolvePropertyName($"edge"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Edge"),
                                                    LinqUtility.ResolvePropertyName($"path"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Path"));

                return(expression);
            }

            if (expression.Type.Name == "ShortestPathData`2")
            {
                string prefix = LinqUtility.MemberNameFromMap(name, "graph", ModelVisitor);

                ModelVisitor.QueryText.AppendFormat(" {{ {0} : {1}, {2} : {3} }} ",
                                                    LinqUtility.ResolvePropertyName($"vertex"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                                    LinqUtility.ResolvePropertyName($"edge"),
                                                    LinqUtility.ResolvePropertyName($"{prefix}_Edge"));

                return(expression);
            }

            ModelVisitor.QueryText.AppendFormat(" {0} ", LinqUtility.ResolvePropertyName(name));

            return(expression);
        }
Ejemplo n.º 3
0
        public void VisitTraversalClause(ITraversalClause traversalClause, QueryModel queryModel, int index)
        {
            string prefix = LinqUtility.MemberNameFromMap(traversalClause.Identifier, "graph", this);

            if (traversalClause.TargetVertex != null)
            {
                QueryText.AppendFormat(" for {0}, {1} in ",
                                       LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                       LinqUtility.ResolvePropertyName($"{prefix}_Edge"));
            }
            else
            {
                QueryText.AppendFormat(" for {0}, {1}, {2} in ",
                                       LinqUtility.ResolvePropertyName($"{prefix}_Vertex"),
                                       LinqUtility.ResolvePropertyName($"{prefix}_Edge"),
                                       LinqUtility.ResolvePropertyName($"{prefix}_Path"));
            }

            if (traversalClause.Min != null && traversalClause.Max != null)
            {
                QueryText.AppendFormat(" {0}..{1} ", traversalClause.Min.Value, traversalClause.Max);
            }

            QueryText.AppendFormat(" {0} ", traversalClause.Direction != null
                ? traversalClause.Direction.Value
                : Utils.EdgeDirectionToString(EdgeDirection.Any));

            if (traversalClause.TargetVertex != null)
            {
                QueryText.Append(" shortest_path ");
                GetAqlExpression(traversalClause.StartVertex, queryModel);
                QueryText.Append(" to ");
                GetAqlExpression(traversalClause.TargetVertex, queryModel);
            }
            else
            {
                GetAqlExpression(traversalClause.StartVertex, queryModel);
            }

            if (string.IsNullOrEmpty(traversalClause.GraphName) == false)
            {
                QueryText.AppendFormat("  graph \"{0}\" ", traversalClause.GraphName);
            }
            else
            {
                StringBuilder edges = new StringBuilder();

                for (int i = 0; i < traversalClause.EdgeCollections.Count; i++)
                {
                    var e = traversalClause.EdgeCollections[i];

                    if (i != 0)
                    {
                        edges.Append(", ");
                    }

                    if (e.Direction.HasValue)
                    {
                        edges.AppendFormat("{0} ", Utils.EdgeDirectionToString(e.Direction.Value));
                    }

                    edges.Append(LinqUtility.ResolvePropertyName(e.CollectionName));
                }

                QueryText.Append(edges);
            }

            if (traversalClause.Options != null)
            {
                QueryText.AppendFormat(" options {0} ", new DocumentSerializer(Db).SerializeWithoutReader(traversalClause.Options.Value));
            }
        }