-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from ZEXSM/feature/sorting-multiple-fields
feature sorting by several fields with indication of direction
- Loading branch information
Showing
8 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
src/OData.QueryBuilder/Conventions/Functions/ISortFunction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace OData.QueryBuilder.Conventions.Functions | ||
{ | ||
public interface ISortFunction | ||
{ | ||
ISortFunction Ascending<T>(T column); | ||
|
||
ISortFunction Descending<T>(T column); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 29 additions & 1 deletion
30
src/OData.QueryBuilder/Expressions/Visitors/ODataOptionOrderByExpressionVisitor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,38 @@ | ||
namespace OData.QueryBuilder.Expressions.Visitors | ||
using OData.QueryBuilder.Conventions.Constants; | ||
using OData.QueryBuilder.Conventions.Functions; | ||
using System; | ||
using System.Linq.Expressions; | ||
|
||
namespace OData.QueryBuilder.Expressions.Visitors | ||
{ | ||
internal class ODataOptionOrderByExpressionVisitor : ODataOptionExpressionVisitor | ||
{ | ||
public ODataOptionOrderByExpressionVisitor() | ||
: base() | ||
{ | ||
} | ||
|
||
protected override string VisitMethodCallExpression(MethodCallExpression methodCallExpression) | ||
{ | ||
switch (methodCallExpression.Method.Name) | ||
{ | ||
case nameof(ISortFunction.Ascending): | ||
var ascending0 = VisitExpression(methodCallExpression.Arguments[0]); | ||
|
||
var ascendingQuery = VisitExpression(methodCallExpression.Object as MethodCallExpression); | ||
var ascendingQueryComma = ascendingQuery == default ? string.Empty : ","; | ||
|
||
return $"{ascendingQuery}{ascendingQueryComma}{ascending0} {QuerySorts.Asc}"; | ||
case nameof(ISortFunction.Descending): | ||
var descending0 = VisitExpression(methodCallExpression.Arguments[0]); | ||
|
||
var descendingQuery = VisitExpression(methodCallExpression.Object as MethodCallExpression); | ||
var descendingQueryComma = descendingQuery == default ? string.Empty : ","; | ||
|
||
return $"{descendingQuery}{descendingQueryComma}{descending0} {QuerySorts.Desc}"; | ||
default: | ||
throw new NotSupportedException($"Method {methodCallExpression.Method.Name} not supported"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters