move projectors a bit around
This commit is contained in:
parent
4c7a280230
commit
4120335a6a
|
|
@ -17,27 +17,14 @@ public static class Extensions
|
|||
query = query.Take(pag.Count);
|
||||
return query;
|
||||
}
|
||||
|
||||
public static async Task<PaginationResponse<TResponseType>> ApplyPaginationRes<TType, TResponseType>(this IQueryable<TType> query, IServiceProvider providers, Pagination pag) where TResponseType : IAutomappedAttribute<TType, TResponseType>, new()
|
||||
public static async Task<PaginationResponse<TResponseType>> ApplyPaginationRes<TType, TResponseType>(this IQueryable<TType> query, IServiceProvider providers, Pagination pag, Expression<Func<TType, TResponseType>>? projector = null) where TResponseType : IAutomappedAttribute<TType, TResponseType>, new()
|
||||
{
|
||||
var totalCount = await query.CountAsync();
|
||||
query = query.Skip(pag.Offset);
|
||||
query = query.Take(pag.Count);
|
||||
var projector = new TResponseType().GetProjectorFrom(providers);
|
||||
|
||||
return new PaginationResponse<TResponseType>
|
||||
{
|
||||
TotalCount = totalCount,
|
||||
Offset = pag.Offset,
|
||||
Count = pag.Count,
|
||||
Data = query.Select(projector).AsAsyncEnumerable()
|
||||
};
|
||||
}
|
||||
public static async Task<PaginationResponse<TResponseType>> ApplyPaginationRes<TType, TResponseType>(this IQueryable<TType> query, IServiceProvider providers, Pagination pag, Expression<Func<TType, TResponseType>> projector) where TResponseType : IAutomappedAttribute<TType, TResponseType>, new()
|
||||
{
|
||||
var totalCount = await query.CountAsync();
|
||||
query = query.Skip(pag.Offset);
|
||||
query = query.Take(pag.Count);
|
||||
if (projector == null)
|
||||
projector = new TResponseType().GetProjectorFrom(providers);
|
||||
|
||||
return new PaginationResponse<TResponseType>
|
||||
{
|
||||
|
|
@ -48,7 +35,7 @@ public static class Extensions
|
|||
};
|
||||
}
|
||||
|
||||
public static async Task<PaginationResponse<TResponseType>> ApplySearchPaginationRes<TType, TResponseType, TEntityBinder>(this IQueryable<TType> query, string? search, IServiceProvider providers, Pagination pag, List<Expression<Func<TType, string, bool>>> matchers)
|
||||
public static async Task<PaginationResponse<TResponseType>> ApplySearchPaginationRes<TType, TResponseType, TEntityBinder>(this IQueryable<TType> query, string? search, IServiceProvider providers, Pagination pag, List<Expression<Func<TType, string, bool>>> matchers, Expression<Func<TType, TResponseType>>? projector = null)
|
||||
where TType : class
|
||||
where TResponseType : IAutomappedAttribute<TType, TResponseType>, new()
|
||||
where TEntityBinder : EntityBinder<TType>
|
||||
|
|
@ -103,7 +90,7 @@ public static class Extensions
|
|||
}
|
||||
}
|
||||
|
||||
return await query.ApplyPaginationRes<TType, TResponseType>(providers, pag);
|
||||
return await query.ApplyPaginationRes<TType, TResponseType>(providers, pag, projector);
|
||||
}
|
||||
|
||||
[Projectable]
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user