|
@ -112,25 +112,19 @@ namespace TaskManager.EntityFramework.Repository |
|
|
PagingParams pagingParams = null,Condition condition = null) |
|
|
PagingParams pagingParams = null,Condition condition = null) |
|
|
{ |
|
|
{ |
|
|
IQueryable<TEntity> query = _dbSet.AsNoTracking(); |
|
|
IQueryable<TEntity> query = _dbSet.AsNoTracking(); |
|
|
|
|
|
|
|
|
// 应用过滤条件
|
|
|
// 应用过滤条件
|
|
|
if (filter != null) |
|
|
if (filter != null) |
|
|
{ |
|
|
{ |
|
|
query = query.Where(filter); |
|
|
query = query.Where(filter); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 应用动态过滤
|
|
|
// 应用动态过滤
|
|
|
if (condition?.Filters != null && condition.Filters.Any()) |
|
|
if (condition?.Filters != null && condition.Filters.Any()) |
|
|
{ |
|
|
{ |
|
|
query = query.ApplyConditionFilters(condition); |
|
|
query = query.ApplyConditionFilters(condition); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 应用分页和排序
|
|
|
// 应用分页和排序
|
|
|
pagingParams ??= new PagingParams(); |
|
|
pagingParams ??= new PagingParams(); |
|
|
|
|
|
|
|
|
var page = await query.ToPagedListAsync(pagingParams); |
|
|
var page = await query.ToPagedListAsync(pagingParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return page; |
|
|
return page; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -151,9 +145,6 @@ namespace TaskManager.EntityFramework.Repository |
|
|
Data = new List<T>(); |
|
|
Data = new List<T>(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class PagingParams |
|
|
public class PagingParams |
|
|
{ |
|
|
{ |
|
|
private const int MaxPageSize = 10000; |
|
|
private const int MaxPageSize = 10000; |
|
@ -171,11 +162,6 @@ namespace TaskManager.EntityFramework.Repository |
|
|
// 新增:过滤条件(键值对)
|
|
|
// 新增:过滤条件(键值对)
|
|
|
public Dictionary<string, string> Filters { get; set; } = new(); |
|
|
public Dictionary<string, string> Filters { get; set; } = new(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static class QueryableExtensions |
|
|
public static class QueryableExtensions |
|
|
{ |
|
|
{ |
|
|
public static IQueryable<T> ApplySort<T>(this IQueryable<T> query, string sortBy, bool isAscending) |
|
|
public static IQueryable<T> ApplySort<T>(this IQueryable<T> query, string sortBy, bool isAscending) |
|
|