Open Closed

Multi-tenant common data #7279


User avatar
0
elhajjh created
  • ABP Framework version: v8.1.3
  • UI Type: Angular
  • Database System: EF Core (SQL Server)

I have some questions about multi-tenancy:

  • In our case, we are using a Single Database for all tenants.
  • I have some data that is common and shared between all tenants, So I need to return the data for the current tenant plus the data that is common to all tenants, which in my case I assume it(the common data) has a value of "NULL" in the tenant field.

Can we do so and how, please?

Thank you


3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    You can make the Entity as a Host Entity

    Then change the current tenant context when querying shared data https://docs.abp.io/en/abp/latest/Multi-Tenancy#change-the-current-tenant

    using (CurrentTenant.Change(null)) // change to host
    {
        return await _productRepository.GetCountAsync();
    }
    
  • User Avatar
    0
    elhajjh created

    Hi Sorry you did not understand me.

    I need to retrieve the data of the current tenant plus the common data in one query

    Means, result = get data where tenant id = current tenant or tenant id = null

    I want this to be automatic for any query

    Thank you

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    ok, you need to add a custom the data filters https://docs.abp.io/en/abp/latest/Data-Filtering#defining-custom-filters

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19