Open Closed

Removing IMultiTenant from Entity resulted with wrong tenant connection string #1188


User avatar
0
selinkoykiran created
  • ABP Framework version: v4.2.2
  • UI type: MVC
  • DB provider: EF Core
  • Tiered (MVC): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Hello ,

We use multitenancy as db per customer approach. We have different db's for different tenants, so we don't want to add TenantId column into our tenant dependent database tables . When we remove IMultiTenant interface from our tenant spesific entities , the application couldn't get tenant connection string correctly , it gives us host connection string. But when we implement IMultiTenant interface it can give us correct tenant connection string. We add some of the screenshot below with IMultiTenant usage or without it. What could be the possible problem here ? Because we can get CurrentTenant informations correctly . But when getting tenant connection string it is all wrong without IMultiTenant implementation ? Could you help about issue.

Thank you.


7 Answer(s)
  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    We use multitenancy as db per customer approach. We have different db's for different tenants, so we don't want to add TenantId column into our tenant dependent database tables .

    Can't say that I understand completely. Assuming you have a Product entity enabled for all entities. Each tenant has their own Product tables. But you don't want them to have TenantId column? Is that the case?

    When we remove IMultiTenant interface from our tenant spesific entities , the application couldn't get tenant connection string correctly , it gives us host connection string. But when we implement IMultiTenant interface it can give us correct tenant connection string.

    I think this makes sense. When you don't have IMultiTenant, connection string falls back to default host connectionstring. Otherwise how to figure out which tenant connection string it is to check in SaasTenantConnectionStrings?

    Please point out if I misunderstood.

  • User Avatar
    0
    selinkoykiran created

    Hello,

    I think there are misunderstandings , could we arrange a desktop sharing session and I can show you from my computer the issue , It will be more understandable I think , Is it ok ?

    Thank you.

  • User Avatar
    0
    gterdem created
    Support Team Senior .NET Developer

    Sorry that I am not able to make screenshare sessions at the moment. Would you mind to explain your situation via this platform so that other users that might be experiencing the same issue can also benefit?

  • User Avatar
    0
    selinkoykiran created

    1- We use multitenancy with db per tenant approach. 2- We store all tenants and connection strings inside host database naturally 3- We have a seperate application which created with suite and this application works with our platform 4- We gave this application inside editions , for example if tenant has standard edition than we don't show anything about this application but if edition is premium tenant and users can see this application and pages 5- This application has its own ef core context and own entities , also has identity and abp spesific tables , too 6 - When we login, we login with tenant and I think when we login with tenant , the abp backend changes our connection string depends on logged in tenant connection string ? 7- After login with tenant if this application spesific entities don't implement IMultiTenant interface than we got error because of wrong connection string but the interesting thing system knows my current tenant Id but the connection string is not correct . 8- When we add IMultitTenant to these entities it resolves correctly. 9- But all abp tables don't have TenantId right ? However they could work correctly ? 10 - So why we need to add IMultiTenant interface to our spesific entities which is stored in tenant depended database already ? When we login it should be getting correct connection string , right ?

    I hope it is clear. Thank you.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi selinkoykiran

    If entity does't implement the IMultiTenant abp will switch to Host side. This is by design.

    public static bool IsMultiTenant(Type type)
    {
        return typeof(IMultiTenant).IsAssignableFrom(type);
    }
    

  • User Avatar
    0
    MichelZ created

    Any chance that this could be improved? We use a one-db-per-tenant approach as well, and having TenantID columns is just distracting :)

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi MichelZ I will discuss with the team.

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