-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull out internal SortOrderHelper. Don't add sort order metadata for …
…default values
- Loading branch information
Showing
3 changed files
with
58 additions
and
36 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; | ||
|
||
namespace Npgsql.EntityFrameworkCore.PostgreSQL.Utilities | ||
{ | ||
static class SortOrderHelper | ||
{ | ||
public static bool IsDefaultSortOrder([NotNull] SortOrder[] sortOrders) | ||
{ | ||
Check.NotNull(sortOrders, nameof(sortOrders)); | ||
|
||
return sortOrders.All(sortOrder => sortOrder != SortOrder.Descending); | ||
} | ||
|
||
public static bool IsDefaultNullSortOrder([NotNull] NullSortOrder[] nullSortOrders, [CanBeNull] SortOrder[] sortOrders) | ||
{ | ||
Check.NotNull(nullSortOrders, nameof(nullSortOrders)); | ||
|
||
for (var i = 0; i < nullSortOrders.Length; i++) | ||
{ | ||
var nullSortOrder = nullSortOrders[i]; | ||
|
||
// We need to consider the ASC/DESC sort order to determine the default NULLS FIRST/LAST sort order. | ||
var sortOrder = i < sortOrders?.Length ? sortOrders[i] : SortOrder.Unspecified; | ||
|
||
if (sortOrder == SortOrder.Descending) | ||
{ | ||
// NULLS FIRST is the default when DESC is specified. | ||
if (nullSortOrder != NullSortOrder.NullsFirst) | ||
{ | ||
return false; | ||
} | ||
} | ||
else | ||
{ | ||
// NULLS LAST is the default when DESC is NOT specified. | ||
if (nullSortOrder != NullSortOrder.NullsLast) | ||
{ | ||
return false; | ||
} | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |