Finbuckle.MultiTenant
Finbuckle.MultiTenant copied to clipboard
If AdjustKey is used on an Entity, it is not possible to add records to the database.
I have several tables, in an Entity Core database, if I use
modelBuilder.Entity<Category>().IsMultiTenant()
.AdjustKey(caregorykey, modelBuilder)
.AdjustIndexes();
it is not possible to add any records to the database, because no TenantId has been assigned to the TenantId property, and as the property is not publicly available, it is not possible to manually set it.
If is use only
modelBuilder.Entity<Category>().IsMultiTenant()
.AdjustIndexes();
I can add records.
Is there some magic trick I am missing that allows us to use the composite key, and still add records to the database?
Thanks
Hi Mark, it should be using the current tenant and assigning it for you. Do you have a repo available I can look at that recreates the issue?
Hi Andrew, I have been putting together a proof-of-concept type app, bringing together different technologies. The repo can be found at https://github.com/MarkLFT/POSManagerPOC. The two key technologies I am implementing first is multi-tenancy and offline syncing.
If you look in the AppDbContext in both API projects you will see where I commented out the code for the Adjust key. If you look in the API.Products.Test project at the integration testing, you can see the tests I have been running to prove the multi-tenancy parts.
Thanks for taking a look at this.
Sorry for the slow response. I'm taking a look at this now.
So I can't run your tests because I don't have the same SQL Server setup that the products API project requires but from looking at the DbContext I think you need to set a default value for TenantNotSetMode
such as Overwrite
so that it will plug in the tenant id for whomever the current tenant is for an operation.