public class ProductCategoryRepository : EfCoreRepository<RailNthzwDbContext, ProductCategory, Guid>, IProductCategoryRepository { public ProductCategoryRepository(IDbContextProvider<RailNthzwDbContext> dbContextProvider) : base(dbContextProvider) { } public async Task<List<ProductCategory>> GetListAsync( Guid? StoreId = null, string StoreName = null, string CategoryName = null, int? CategoryOrder = null, string Remarks = null, string Sorting = null, int MaxResultCount = int.MaxValue, int SkipCount = 0, CancellationToken cancellationToken = default) { var query = ApplyFilter(await GetQueryableAsync(), StoreId, StoreName, CategoryName, CategoryOrder, Remarks); return await query.PageBy(SkipCount, MaxResultCount).ToListAsync(cancellationToken); } public async Task<long> GetCountAsync( Guid? StoreId = null, string StoreName = null, string CategoryName = null, int? CategoryOrder = null, string Remarks = null, CancellationToken cancellationToken = default) { var query = ApplyFilter(await GetDbSetAsync(), StoreId, StoreName, CategoryName, CategoryOrder, Remarks); return await query.LongCountAsync(GetCancellationToken(cancellationToken)); } protected virtual IQueryable<ProductCategory> ApplyFilter( IQueryable<ProductCategory> query, Guid? StoreId = null, string StoreName = null, string CategoryName = null, int? CategoryOrder = null, string Remarks = null) { return query .WhereIf(StoreId.HasValue, e => e.StoreId == StoreId.Value) .WhereIf(!string.IsNullOrEmpty(StoreName), e => e.StoreName.Contains(StoreName)) .WhereIf(!string.IsNullOrEmpty(CategoryName), e => e.CategoryName.Contains(CategoryName)) .WhereIf(CategoryOrder.HasValue, e => e.CategoryOrder == CategoryOrder.Value) .WhereIf(!string.IsNullOrEmpty(Remarks), e => e.Remarks.Contains(Remarks)); } }

ProductCategoryRepository - EF Core Repository for Product Categories

原文地址: https://www.cveoy.top/t/topic/p0Ck 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录