sdk/dotnet/src/Microsoft.Datasync.Client/Query/Linq/QueryTranslator.cs
/// <summary>
/// Add an ordering expression to the query
/// </summary>
/// <param name="expression">An ordering method call expression</param>
/// <param name="ascending">True if the ordering is ascending, false otherwise</param>
/// <param name="prepend">True to prepend the ordering to the list</param>
Add an ordering expression to the query
Add an ordering expression to the query
internal protected void AddOrdering(MethodCallExpression expression, bool ascending, bool prepend)
        {
            if (expression.IsValidLambdaExpression(out LambdaExpression lambda) && lambda!.Body is MemberExpression memberExpression)
            {
                string memberName = FilterBuildingExpressionVisitor.GetTableMemberName(memberExpression, ContractResolver);
                if (memberName != null)
                {
                    var node = new OrderByNode(new MemberAccessNode(null, memberName), ascending);
                    if (prepend)
                    {
                        QueryDescription.Ordering.Insert(0, node);
                    }
                    else
                    {
                        QueryDescription.Ordering.Add(node);
                    }
                }
            }
            else
            {
                throw new NotSupportedException($"'{expression?.Method.Name}' query expressions must consist of members only.");
            }
        }
internal protected void AddOrdering ( MethodCallExpression expression , bool ascending , bool prepend ) { if ( expression . IsValidLambdaExpression ( out LambdaExpression lambda ) && lambda ! . Body is MemberExpression memberExpression ) { string memberName = FilterBuildingExpressionVisitor . GetTableMemberName ( memberExpression , ContractResolver ) ; if ( memberName != null ) { var node = new OrderByNode ( new MemberAccessNode ( null , memberName ) , ascending ) ; if ( prepend ) { QueryDescription . Ordering . Insert ( 0 , node ) ; } else { QueryDescription . Ordering . Add ( node ) ; } } } else { throw new NotSupportedException ( $" ' { expression ? . Method . Name } ' query expressions must consist of members only. " ) ; } }
Add an ordering expression to the query
Add an ordering expression to the query
// We only allow keySelectors that are x => x.member expressions (i.e. MemberAccessNode). // Anything else will result in a NotSupportedException
expression
MethodCallExpression
An ordering method call expression
An ordering method call expression
ascending
bool
True if the ordering is ascending, false otherwise
True if the ordering is ascending false otherwise
prepend
bool
True to prepend the ordering to the list
True to prepend the ordering to the list