コード例 #1
0
        /// <summary>
        /// Creates a <see cref="DbOrderByExpression"/> that represents ordering the result set.
        /// </summary>
        /// <param name="dbSelectQuery">The target <see cref="DbQuery{TQueryExpression}"/>.</param>
        /// <param name="expressionSelector">A function used to specify an element in the 'ORDER BY' clause.</param>
        /// <param name="orderByExpressionType">Specifies the sort order direction.</param>
        /// <returns></returns>
        public static DbQuery <DbSelectExpression> OrderBy(this DbQuery <DbSelectExpression> dbSelectQuery, Func <DbExpressionFactory, DbExpression> expressionSelector, DbOrderByExpressionType orderByExpressionType)
        {
            var dbExpression = (DbExpression)DbExpressionFactory.MakeOrderBy(orderByExpressionType, expressionSelector(DbExpressionFactory));

            if (!dbSelectQuery.QueryExpression.OrderByExpression.IsNull())
            {
                dbExpression = DbExpressionFactory.List(new[] { dbSelectQuery.QueryExpression.OrderByExpression, dbExpression });
            }
            dbSelectQuery.QueryExpression.OrderByExpression = dbExpression;
            return(dbSelectQuery);
        }