当前位置: 首页>>代码示例>>C#>>正文


C# QueryExpression.OrderBy方法代码示例

本文整理汇总了C#中QueryExpression.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# QueryExpression.OrderBy方法的具体用法?C# QueryExpression.OrderBy怎么用?C# QueryExpression.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QueryExpression的用法示例。


在下文中一共展示了QueryExpression.OrderBy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddOrderingForPaging

        /// <summary>
        /// Adds an ordering expression for each key property 
        /// </summary>
        /// <param name="source">The query to add ordering to</param>
        /// <returns>The result of adding the ordering expressions</returns>
        private LinqOrderByExpression AddOrderingForPaging(QueryExpression source)
        {
            ExceptionUtilities.CheckArgumentNotNull(source, "source");

            var orderByExpression = source as LinqOrderByExpression;

            ExceptionUtilities.CheckObjectNotNull(this.expectedEntitySet, "No entity set expected");

            // the product will sort key properties alphabetically
            foreach (var key in this.expectedEntitySet.EntityType.AllKeyProperties.OrderBy(p => p.Name))
            {
                // if the expression already has other orderby clauses, use thenby
                if (orderByExpression == null)
                {
                    orderByExpression = source.OrderBy(o => o.Property(key.Name));
                }
                else
                {
                    orderByExpression = orderByExpression.ThenBy(o => o.Property(key.Name));
                }
            }

            ExceptionUtilities.CheckObjectNotNull(orderByExpression, "Failed to build orderby expression, entity type had no keys");
            return orderByExpression;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:30,代码来源:ODataUriEvaluator.cs

示例2: ProcessOrderBy

        /// <summary>
        /// Processes the $orderby portion of the uri. Will also add special ordering if the response would be paged.
        /// </summary>
        /// <param name="source">The source expression</param>
        /// <returns>The result of processing the orderby</returns>
        private QueryExpression ProcessOrderBy(QueryExpression source)
        {
            ExceptionUtilities.CheckArgumentNotNull(source, "source");

            var queryBasedUri = this.currentUri as QueryBasedODataUri;
            if (queryBasedUri != null && queryBasedUri.OrderByExpressions.Count > 0)
            {
                LinqOrderByExpression orderedQuery = null;

                // rebuild the orderby expression using OrderBy and ThenBy
                foreach (var orderby in queryBasedUri.OrderByExpressions)
                {
                    ExceptionUtilities.Assert(orderby.AreDescending.Count == orderby.KeySelectors.Count, "Orderby expression had mismatched counts");
                    ExceptionUtilities.Assert(orderby.KeySelectors.Count > 0, "Orderby expression did not have any key selectors");

                    // handle the first key selector seperately, since the remainder will need to use ThenBy
                    int startIndex = 0;
                    if (orderedQuery == null)
                    {
                        var ascending = !orderby.AreDescending[0];
                        var lambda = orderby.KeySelectors[0];
                        startIndex = 1;

                        if (ascending)
                        {
                            orderedQuery = source.OrderBy(o => this.RewriteLambda(o, lambda));
                        }
                        else
                        {
                            orderedQuery = source.OrderByDescending(o => this.RewriteLambda(o, lambda));
                        }
                    }

                    // handle the remaining key selectors
                    for (int i = startIndex; i < orderby.AreDescending.Count; i++)
                    {
                        var ascending = !orderby.AreDescending[i];
                        var lambda = orderby.KeySelectors[i];

                        if (ascending)
                        {
                            orderedQuery = orderedQuery.ThenBy(o => this.RewriteLambda(o, lambda));
                        }
                        else
                        {
                            orderedQuery = orderedQuery.ThenByDescending(o => this.RewriteLambda(o, lambda));
                        }
                    }
                }

                source = orderedQuery;
            }
            else
            {
                // if this uri was not built from a query, then we cannot handle orderby expressions
                var orderByString = this.currentUri.OrderBy;
                ExceptionUtilities.Assert(string.IsNullOrEmpty(orderByString), "Non-query-based uri had non-empty orderby string '{0}' which cannot be processed", orderByString);
            }

            // add ordering if the response would be paged
            if (this.IsPaged())
            {
                source = this.AddOrderingForPaging(source);
            }

            return source;
        }
开发者ID:larsenjo,项目名称:odata.net,代码行数:72,代码来源:ODataUriEvaluator.cs


注:本文中的QueryExpression.OrderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。