Open Closed

Customers with multiple tenants #6263


User avatar
0
pablo@ccalp.net created
  • ABP Framework version: v7.4.0
  • UI Type: Angular
  • Database System: EF Core (SQL Server)

Hello, Is the following scenario possible to accomplish within the framework? How? We are implementing a Database Per Tenant multitenancy architecture. Our customers have multiple facilities and they need to create reports across those facilities, so we need to do cross-database queries, we are hosting in Azure so I don't want to do cross-database queries but be able to host the tenant facilities in a single database so that it is easier to query across the facility tenants.

Is it possible to have a multiple hybrid approach? for example:

Customer-A Customer-A-DB (SQL Database) Facility-a (TenantId: xxxx-xxxxx-xxxx) Facility-b (TenantId: xxxx-xxxxx-xxxx) Facility-c (TenantId: xxxx-xxxxx-xxxx)

Customer-B Customer-B-DB (SQL Database) Facility-a (TenantId: xxxx-xxxxx-xxxx) Facility-b (TenantId: xxxx-xxxxx-xxxx) Facility-c (TenantId: xxxx-xxxxx-xxxx)

Customer-C Customer-C-DB (SQL Database) Facility-a (TenantId: xxxx-xxxxx-xxxx) Facility-b (TenantId: xxxx-xxxxx-xxxx) Facility-c (TenantId: xxxx-xxxxx-xxxx)

TIA.


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

    Hi,

    As I understand, a customer is a tenant. a facility can belong to multiple customers.

    Just an idea:

    The Facility entity should not implement the IMultiTenant interface, so It will be in the host database.

    public class Facility: ...
    {
        public List<Guid> TenantIds {get; set;}
    }
    
    public class TestAppService:....
    {
        private readonly IRepository<Facility, Guid> _reopsitory;
        .....    
     
        public async Task GetReportAsync()
        {
            var currentTenantId = CurrentTenant.GetId();
            //Switch to host
            using(CurrentTenant.Change(null))
            {
              var result = await  _reopsitory.GetListAsync(x => x.TenantIds.Contains(currentTenantId));
            }
            
        }
    }
    
  • User Avatar
    0
    pablo@ccalp.net created

    Thanks for your prompt response, maybe I didn't explain well the scenario, hopefully, this diagram will help. I need to implement multiple Hybrid architectures where some tenants share a single database while some tenants may have their own database.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I need to implement multiple Hybrid architectures where some tenants share a single database while some tenants may have their own database.

    Yes, it's possible, but I still don't know what's blocked you.

  • User Avatar
    0
    pablo@ccalp.net created

    I need some guidance on how to accomplish it, it is not clear in the documentation for creating tenants, that's my block.

    Update: I created 3 tenants with the same connection-string. When creating the first one, the database was created, then I created the two additional tenants with the same connection but the admin user and role records were not created.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    When creating the first one, the database was created, then I created the two additional tenants with the same connection but the admin user and role records were not created.

    Could you share the steps to reproduce? I will check it out. thanks

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