Open Closed

Join Host and Tenant Data in one query #1329


User avatar
0
falsharif created
  • ABP Framework version: v4.3
  • UI type: / Blazor
  • DB provider: EF Core /
  • Tiered (MVC) or Identity Server Separated (Angular): yes / no
  • Exception message and stack trace:
  • Steps to reproduce the issue:

hello, i have a products entity , each product can have a product category and product subcategory. in some situations, the product exists in the tenant but the category and sub category only in the host.

i created a custom repository where i have this code where i implemenet datafilter to get host product categories and sub categories :

this unfortunately doesnt work and keeps returning null values for the product category and subcategory. i checked the response in GetHostProductCategories() function and shows the data there if do a .ToList().

I am tring to eventually achieve functionality where if the product category is not in this tenant, then we get it from host..

PS: BOTH TENANT AND HOST ARE IN THE SAME DATABASE

    public virtual async Task<IQueryable<ProductWithNavigationProperties>> GetQueryForNavigationPropertiesAsync(
        Guid? tenantId=null)
    {
       
            var products = (await GetDbSetAsync());
            
            return from product in (products)
                join productCategory in await GetHostProductCategories()
                    on product.ProductCategoryId equals productCategory.Id into productCategories
                from productCategory in productCategories.DefaultIfEmpty()
                join productSubCategory in await GetHostProductSubCategories()
                    on product.ProductSubCategoryId equals productSubCategory.Id into productSubCategories
                from productSubCategory in productSubCategories.DefaultIfEmpty()
                select new ProductWithNavigationProperties()
                {
                    Product = product,
                    ProductCategory = productCategory,
                    ProductSubCategory = productSubCategory,
                };
        
    }
    
     private async Task<IQueryable<ProductCategory>> GetHostProductCategories()
    {

        using (DataFilter.Disable<IMultiTenant>())
        {
           return (await GetDbContextAsync()).ProductCategories;
        }
    }

    private async Task<IQueryable<ProductSubCategory>> GetHostProductSubCategories()
    {
        using (DataFilter.Disable<IMultiTenant>())
        {
            return(await GetDbContextAsync()).ProductSubCategories;
        }
    }
    
    
    
    
    

2 Answer(s)
  • User Avatar
    0
    cotur created

    Hi,

    You can try to disable multi-tenacy filter then exceture your query, but be careful, you also need to filter your tenant entities by yourself.

    https://docs.abp.io/en/abp/latest/Multi-Tenancy#data-filtering-disable-the-multi-tenancy-filter

  • User Avatar
    0
    ServiceBot created
    Support Team Automatic process manager

    This question has been automatically marked as stale because it has not had recent activity.

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11