/// <summary> /// Translates resource bound expression tree to a URI. /// </summary> /// <param name='context'>Data context used to generate type names for types.</param> /// <param name="addTrailingParens">flag to indicate whether generated URI should include () if leaf is ResourceSet</param> /// <param name="e">The expression to translate</param> /// <param name="uri">uri</param> /// <param name="version">version for query</param> internal static void Translate(DataServiceContext context, bool addTrailingParens, Expression e, out Uri uri, out Version version) { var writer = new UriWriter(context); writer.Visit(e); string fullUri = writer.uriBuilder.ToString(); if (writer.alias.Any()) { if (fullUri.IndexOf(UriHelper.QUESTIONMARK) > -1) { fullUri += UriHelper.AMPERSAND; } else { fullUri += UriHelper.QUESTIONMARK; } foreach (var kv in writer.alias) { fullUri += kv.Key; fullUri += UriHelper.EQUALSSIGN; fullUri += kv.Value; fullUri += UriHelper.AMPERSAND; } fullUri = fullUri.Substring(0, fullUri.Length - 1); } uri = UriUtil.CreateUri(fullUri, UriKind.Absolute); version = writer.uriVersion; }
/// <summary>Builds the Uri for the expression passed in.</summary> /// <param name="e">The expression to translate into a Uri</param> /// <returns>Query components</returns> internal QueryComponents Translate(Expression e) { Uri uri; Version version; bool addTrailingParens = false; Dictionary <Expression, Expression> normalizerRewrites = null; // short cut analysis if just a resource set or singleton resource. // note - to be backwards compatible with V1, will only append trailing () for queries // that include more then just a resource set. if (!(e is QueryableResourceExpression)) { normalizerRewrites = new Dictionary <Expression, Expression>(ReferenceEqualityComparer <Expression> .Instance); e = Evaluator.PartialEval(e); e = ExpressionNormalizer.Normalize(e, normalizerRewrites); e = ResourceBinder.Bind(e, this.Context); addTrailingParens = true; } UriWriter.Translate(this.Context, addTrailingParens, e, out uri, out version); ResourceExpression re = e as ResourceExpression; Type lastSegmentType = re.Projection == null ? re.ResourceType : re.Projection.Selector.Parameters[0].Type; LambdaExpression selector = re.Projection == null ? null : re.Projection.Selector; return(new QueryComponents(uri, version, lastSegmentType, selector, normalizerRewrites)); }
/// <summary> /// Translates resource bound expression tree to a URI. /// </summary> /// <param name='context'>Data context used to generate type names for types.</param> /// <param name="addTrailingParens">flag to indicate whether generated URI should include () if leaf is ResourceSet</param> /// <param name="e">The expression to translate</param> /// <param name="uri">uri</param> /// <param name="version">version for query</param> internal static void Translate(DataServiceContext context, bool addTrailingParens, Expression e, out Uri uri, out Version version) { var writer = new UriWriter(context); writer.leafResource = addTrailingParens ? (e as QueryableResourceExpression) : null; writer.Visit(e); uri = UriUtil.CreateUri(writer.uriBuilder.ToString(), UriKind.Absolute); version = writer.uriVersion; }