private object ProcessTop(TopQueryNode top) { var processedLimit = ProcessNode(top.Amount); _sparqlModel.Limit = Convert.ToInt32(processedLimit); return(ProcessNode(top.Collection)); }
/// <summary> /// Processes the top operator (if any) and returns the combined query. /// </summary> /// <param name="query">The query tree constructed so far.</param> /// <param name="top">The top amount or null if none was specified.</param> /// <returns> /// The unmodified <paramref name="query"/> if no top is specified or the combined /// query tree including the top operator if it was specified. /// </returns> private static QueryNode ProcessTop(QueryNode query, int? top) { ExceptionUtils.CheckArgumentNotNull(query, "query"); if (top.HasValue) { CollectionQueryNode entityCollection = query.AsEntityCollectionNode(); if (entityCollection == null) { throw new ODataException(Strings.MetadataBinder_TopNotApplicable); } int topValue = top.Value; if (topValue < 0) { throw new ODataException(Strings.MetadataBinder_TopRequiresNonNegativeInteger(topValue.ToString(CultureInfo.CurrentCulture))); } query = new TopQueryNode() { Collection = entityCollection, Amount = new ConstantQueryNode { Value = topValue } }; } return query; }
/// <summary> /// Translates a top/take operation. /// </summary> /// <param name="topNode">The top node to translate.</param> /// <returns>The translated expression which evaluates to the result of the top operation.</returns> protected virtual Expression TranslateTop(TopQueryNode topNode) { ExceptionUtils.CheckArgumentNotNull(topNode, "topNode"); ExceptionUtils.CheckArgumentNotNull(topNode.Amount, "topNode.Amount"); Expression collectionExpression = this.Translate(topNode.Collection); Expression amountExpression = this.Translate(topNode.Amount); // TODO: eventually we will have to support this on Enumerable as well (as it can happen on expansions) return Expression.Call( typeof(Queryable), TakeMethodName, new Type[] { topNode.Collection.ItemType.GetInstanceType(this.model) }, collectionExpression, amountExpression); }
private object ProcessTop(TopQueryNode top) { var processedLimit = ProcessNode(top.Amount); _sparqlModel.Limit = Convert.ToInt32(processedLimit); return ProcessNode(top.Collection); }