private void ConvertSpanPath(
            ObjectFullSpanRewriter.SpanPathInfo parentInfo,
            List <string> navPropNames,
            int pos)
        {
            NavigationProperty index = (NavigationProperty)null;

            if (!parentInfo.DeclaringType.NavigationProperties.TryGetValue(navPropNames[pos], true, out index))
            {
                throw new InvalidOperationException(Strings.ObjectQuery_Span_NoNavProp((object)parentInfo.DeclaringType.FullName, (object)navPropNames[pos]));
            }
            if (parentInfo.Children == null)
            {
                parentInfo.Children = new Dictionary <NavigationProperty, ObjectFullSpanRewriter.SpanPathInfo>();
            }
            ObjectFullSpanRewriter.SpanPathInfo parentInfo1 = (ObjectFullSpanRewriter.SpanPathInfo)null;
            if (!parentInfo.Children.TryGetValue(index, out parentInfo1))
            {
                parentInfo1 = new ObjectFullSpanRewriter.SpanPathInfo(ObjectFullSpanRewriter.EntityTypeFromResultType(index));
                parentInfo.Children[index] = parentInfo1;
            }
            if (pos >= navPropNames.Count - 1)
            {
                return;
            }
            this.ConvertSpanPath(parentInfo1, navPropNames, pos + 1);
        }
        private static EntityType EntityTypeFromResultType(NavigationProperty navProp)
        {
            EntityType entityType = (EntityType)null;

            ObjectFullSpanRewriter.TryGetEntityType(navProp.TypeUsage, out entityType);
            return(entityType);
        }
        internal ObjectFullSpanRewriter(
            DbCommandTree tree,
            DbExpression toRewrite,
            Span span,
            AliasGenerator aliasGenerator)
            : base(tree, toRewrite, aliasGenerator)
        {
            EntityType entityType = (EntityType)null;

            if (!ObjectFullSpanRewriter.TryGetEntityType(this.Query.ResultType, out entityType))
            {
                throw new InvalidOperationException(Strings.ObjectQuery_Span_IncludeRequiresEntityOrEntityCollection);
            }
            ObjectFullSpanRewriter.SpanPathInfo parentInfo = new ObjectFullSpanRewriter.SpanPathInfo(entityType);
            foreach (Span.SpanPath span1 in span.SpanList)
            {
                this.AddSpanPath(parentInfo, span1.Navigations);
            }
            this._currentSpanPath.Push(parentInfo);
        }
示例#4
0
        internal static bool TryRewrite(
            DbQueryCommandTree tree, Span span, MergeOption mergeOption, AliasGenerator aliasGenerator, out DbExpression newQuery,
            out SpanIndex spanInfo)
        {
            newQuery = null;
            spanInfo = null;

            ObjectSpanRewriter rewriter  = null;
            var requiresRelationshipSpan = Span.RequiresRelationshipSpan(mergeOption);

            // Potentially perform a rewrite for span.
            // Note that the public 'Span' property is NOT used to retrieve the Span instance
            // since this forces creation of a Span object that may not be required.
            if (span != null &&
                span.SpanList.Count > 0)
            {
                rewriter = new ObjectFullSpanRewriter(tree, tree.Query, span, aliasGenerator);
            }
            else if (requiresRelationshipSpan)
            {
                rewriter = new ObjectSpanRewriter(tree, tree.Query, aliasGenerator);
            }

            if (rewriter != null)
            {
                rewriter.RelationshipSpan = requiresRelationshipSpan;
                newQuery = rewriter.RewriteQuery();
                if (newQuery != null)
                {
                    Debug.Assert(
                        rewriter.SpanIndex != null || tree.Query.ResultType.EdmEquals(newQuery.ResultType),
                        "Query was rewritten for Span but no SpanIndex was created?");
                    spanInfo = rewriter.SpanIndex;
                }
            }

            return(spanInfo != null);
        }
        internal static bool TryRewrite(
            DbQueryCommandTree tree, Span span, MergeOption mergeOption, AliasGenerator aliasGenerator, out DbExpression newQuery,
            out SpanIndex spanInfo)
        {
            newQuery = null;
            spanInfo = null;

            ObjectSpanRewriter rewriter = null;
            var requiresRelationshipSpan = Span.RequiresRelationshipSpan(mergeOption);

            // Potentially perform a rewrite for span.
            // Note that the public 'Span' property is NOT used to retrieve the Span instance
            // since this forces creation of a Span object that may not be required.
            if (span != null
                && span.SpanList.Count > 0)
            {
                rewriter = new ObjectFullSpanRewriter(tree, tree.Query, span, aliasGenerator);
            }
            else if (requiresRelationshipSpan)
            {
                rewriter = new ObjectSpanRewriter(tree, tree.Query, aliasGenerator);
            }

            if (rewriter != null)
            {
                rewriter.RelationshipSpan = requiresRelationshipSpan;
                newQuery = rewriter.RewriteQuery();
                if (newQuery != null)
                {
                    Debug.Assert(
                        rewriter.SpanIndex != null || tree.Query.ResultType.EdmEquals(newQuery.ResultType),
                        "Query was rewritten for Span but no SpanIndex was created?");
                    spanInfo = rewriter.SpanIndex;
                }
            }

            return (spanInfo != null);
        }