SaaS- Tenant Specific Lookup Data in Shared Database

前端 未结 4 1988
野性不改
野性不改 2021-01-28 06:17

I am developing multitenant SaaS based application and going with Shared Database for storing all the tenant records with help of TenantId column.

Now the problem is i h

4条回答
  •  没有蜡笔的小新
    2021-01-28 07:11

    You can merge the tables leaving TenantId as NULL for records you wish to not be Tenant specific.

    Games

    Id
    TenantId
    GameName
    

    The you can query that table in a Join with:

    ...
    FROM
        Games
        INNER JOIN UserGames ON
            UserGames.GameId = Games.Id
    
    WHERE
        Games.TenantId = @tenantId OR
        Games.TenantId IS NULL
    

    This will save you the trouble of ensuring that the Id is unique between the tables, unless you are using a UNIQUEIDENTIFIER for the Id.

提交回复
热议问题