maliming
4 years ago
No known key found for this signature in database
GPG Key ID: 96224957E51C89E
4 changed files with
20 additions and
3 deletions
-
framework/src/Volo.Abp.Core/System/Linq/AbpQueryableExtensions.cs
-
framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs
-
framework/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs
-
framework/src/Volo.Abp.MongoDB/Volo/Abp/Domain/Repositories/MongoDB/MongoDbRepository.cs
|
|
|
@ -95,4 +95,21 @@ public static class AbpQueryableExtensions |
|
|
|
? (TQueryable)query.Where(predicate) |
|
|
|
: query; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Order a <see cref="IQueryable{T}"/> by given predicate if given condition is true.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="query">Queryable to apply filtering</param>
|
|
|
|
/// <param name="condition">A boolean value</param>
|
|
|
|
/// <param name="sorting">Order the query</param>
|
|
|
|
/// <returns>Order or not order query based on <paramref name="condition"/></returns>
|
|
|
|
public static TQueryable OrderByIf<T, TQueryable>([NotNull] this TQueryable query, bool condition, string sorting) |
|
|
|
where TQueryable : IQueryable<T> |
|
|
|
{ |
|
|
|
Check.NotNull(query, nameof(query)); |
|
|
|
|
|
|
|
return condition |
|
|
|
? (TQueryable)Dynamic.Core.DynamicQueryableExtensions.OrderBy(query, sorting) |
|
|
|
: query; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -252,7 +252,7 @@ public class EfCoreRepository<TDbContext, TEntity> : RepositoryBase<TEntity>, IE |
|
|
|
: await GetDbSetAsync(); |
|
|
|
|
|
|
|
return await queryable |
|
|
|
.OrderBy(sorting) |
|
|
|
.OrderByIf<TEntity, IQueryable<TEntity>>(!sorting.IsNullOrWhiteSpace(), sorting) |
|
|
|
.PageBy(skipCount, maxResultCount) |
|
|
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
|
|
|
} |
|
|
|
|
|
|
|
@ -285,7 +285,7 @@ public class MemoryDbRepository<TMemoryDbContext, TEntity> : RepositoryBase<TEnt |
|
|
|
CancellationToken cancellationToken = default) |
|
|
|
{ |
|
|
|
return (await GetQueryableAsync()) |
|
|
|
.OrderBy(sorting) |
|
|
|
.OrderByIf<TEntity, IQueryable<TEntity>>(!sorting.IsNullOrWhiteSpace(), sorting) |
|
|
|
.PageBy(skipCount, maxResultCount) |
|
|
|
.ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -465,7 +465,7 @@ public class MongoDbRepository<TMongoDbContext, TEntity> |
|
|
|
cancellationToken = GetCancellationToken(cancellationToken); |
|
|
|
|
|
|
|
return await (await GetMongoQueryableAsync(cancellationToken)) |
|
|
|
.OrderBy(sorting) |
|
|
|
.OrderByIf<TEntity, IQueryable<TEntity>>(!sorting.IsNullOrWhiteSpace(), sorting) |
|
|
|
.As<IMongoQueryable<TEntity>>() |
|
|
|
.PageBy<TEntity, IMongoQueryable<TEntity>>(skipCount, maxResultCount) |
|
|
|
.ToListAsync(cancellationToken); |
|
|
|
|