is there any recommended entity structure for multi tenancy in boilerplate?
should we use composite key or we should go for unique identity?
I was using composite primary key then I have issues with soft delete .
if using unique identity then hard to maintain uniqueness per tenant.
Please recommend the most preferred way
5 Answer(s)
-
0
We suggest to use a single Id property (int, long, Guid... whatever you like) and implement IMustHaveTenant (or IMayHaveTenant if this entity can be a host entity). If you want, you can create a unique index for TenantId, Id.
-
0
I was using the database generated unique index for id .But I have a following scenario
Every Tenant have unique InvoiceNo
Tenant 1 --- invoice 001 Tenant 2 --- invoice 001
if i make TenantID and InvoiceNo as composite primary key then I dont need to write much code if I use id then every time i have to check that Tenant in use have this invoice or not before entrying the new invoice .
please let me know the better way to implement the above condition
thanks
-
0
+1, i'm in the same case for a lot of table and I was going to ask the same question :D
For some tables, I use an unique PK which is not guid (for example a datetime or int; for optimisation/size purpose). Most of my case are separate databases with column TenantId set. But if I need to merge them into one db; TenantId will be correct but PK will be duplicated. (logic)
If I create a composite key (that's the only way I see ...), i'll rewrite a lot of code since almost all of my tables have IMustHaveTenant. And create a lot of DTO to remove the tenantId property.
But that's the only way that I see; so i'm going to go on this way.
Waiting for your reply/suggestions if you have another idea ;)
-
0
hope we get the reply soon :)
-
0
The best solution I found is that for multiple keys: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/299#issuecomment-71915096">https://github.com/aspnetboilerplate/as ... t-71915096</a>