简体   繁体   中英

ABP and .Net 5 problem retrieving records

I am working with ABP 6.5.0. I have an App Service that retrieves all the tenants running the GetAll method.

I have overwrite the CreateFilteredQuery and it runs the following code:

protected override IQueryable<Tenant> CreateFilteredQuery(PagedBusinessResultRequestDto input)
    {
        IQueryable<Tenant> result = null;

        result = Repository
                   .GetAll()
                       .Include(b => b.Branches)
                           .ThenInclude(bc => bc.BranchCategories)
                   .WhereIf(!input.Keywords.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Keywords) || x.TenantDescription.Contains(input.Keywords))
                   .Where(x => x.Id != AppConsts.DefaultTenantId && x.IsActive && x.IsValid);

        return result;
    }

When I call the Rest API (Business.GetAll), the tenant records are retrieved, but these records don't include the Branches and BrachCategories when the user is logged into the application. However, when the user is not logged into the app, it works as expected.

Something interesting I found was debugging the code. If I review the result variable before the CreateFilteredQuery method finishes the execution, the branch and branchCategories records are retrieved correctly. However, if I don't review the result variable, branch and branchCategories records are not retrived.

Any idea what could be happening here?

Thanks in advances.

I fixed this problem doing this:

public override async Task<PagedResultDto<BusinessDto>> GetAllAsync(PagedBusinessResultRequestDto input)
        {
            using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MustHaveTenant))
            {
                return await base.GetAllAsync(input);
            }
        }

I had tried this other code and it didn't work, but for some reason it is incorrectly, I am thinking that Abp applies automatically a filter the result variable.

public override Task<PagedResultDto<BusinessDto>> GetAllAsync(PagedBusinessResultRequestDto input)
        {
            Task<PagedResultDto<BusinessDto>> result;
            using (_unitOfWorkManager.Current.DisableFilter(AbpDataFilters.MustHaveTenant))
            {
                result = base.GetAllAsync(input);
            }
            return result;
        }

Thanks everyone for your time.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM