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

Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    liangshiwei created
    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();
    }
    
    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • 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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    liangshiwei created
    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

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on September 09, 2026, 11:56
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.