简体   繁体   English

ABP 和.Net 5 检索记录的问题

[英]ABP and .Net 5 problem retrieving records

I am working with ABP 6.5.0.我正在使用 ABP 6.5.0。 I have an App Service that retrieves all the tenants running the GetAll method.我有一个应用服务,它检索所有运行 GetAll 方法的租户。

I have overwrite the CreateFilteredQuery and it runs the following code:我已经覆盖了 CreateFilteredQuery,它运行以下代码:

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.当我调用 Rest API (Business.GetAll) 时,会检索租户记录,但是当用户登录到应用程序时,这些记录不包括BranchesBrachCategories 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.如果我在CreateFilteredQuery方法完成执行之前查看result变量,则可以正确检索分支branchCategories记录。 However, if I don't review the result variable, branch and branchCategories records are not retrived.但是,如果我不查看result变量,则不会检索branchbranchCategories记录。

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.我试过这个其他代码但它没有工作,但由于某种原因它不正确,我认为 Abp 自动应用过滤器result变量。

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.感谢大家的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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