Finbuckle.MultiTenant icon indicating copy to clipboard operation
Finbuckle.MultiTenant copied to clipboard

If AdjustKey is used on an Entity, it is not possible to add records to the database.

Open MarkLFT opened this issue 1 year ago • 4 comments

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

MarkLFT avatar May 30 '23 08:05 MarkLFT

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?

AndrewTriesToCode avatar Jun 01 '23 15:06 AndrewTriesToCode

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.

MarkLFT avatar Jun 02 '23 01:06 MarkLFT

Sorry for the slow response. I'm taking a look at this now.

AndrewTriesToCode avatar Jul 13 '23 00:07 AndrewTriesToCode

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.

AndrewTriesToCode avatar Jul 13 '23 02:07 AndrewTriesToCode