radzenhq / radzen-blazor-studio

Sample applications created with Radzen Blazor Studio
https://www.radzen.com/blazor-studio
16 stars 2 forks source link

Blazor Server App - Saving Data while logged in as a Tenant fails to save TenantId value in Tenant column - (uniqueidentifier) #100

Closed 274188A closed 1 year ago

274188A commented 1 year ago

Radzen Blazor Studio 1.6.0 Blazor Server App MSSQL Server DB

STEPS Logon as Tenant Create a record. Check DB for TenantId value in Table.

No value in Table - just NULL. Other values saved correctly.

Possible Causes The PK and TenantID columns are of type uniqueidentifier (guid)

akorchev commented 1 year ago

Radzen Blazor Studio will not automatically set the tenantid. You need to update your page to do that.

274188A commented 1 year ago

I don't understand. When you say "set the tenant id" do you mean set the actual value of the tenant logged in?

My table already has the column there - but surely the code knows who is logged in and what their tenant id is?

274188A commented 1 year ago

I'm not expecting radzen studio to magically create a tenantid column for me. but the code should be able to set a value in that tenantid column when data is saved by a particular tenant

akorchev commented 1 year ago

Radzen Blazor Studio does not know what a column represents. This is why it can't and won't set tenantid automatically.

274188A commented 1 year ago

ok - I see. So if a tenant saves something, then that data is exposed to every other tenant until somebody manually goes into the database and set the tenant ID. Am I understanding that right?

274188A commented 1 year ago

All we need here is an agreed 'convention' for what the 'tenantId' column is "called" or "named" in a db. Maybe configurable via appsettings even?

How about agreeing on a name that is looked for and saving to that?

I humbly implore you to consider changing your approach as really it's not a workable solution when data is saved in real time by various tenant.

One of the underpinning principles of multi-tenant is that the data from different tenants is kept quite separate logically.

akorchev commented 1 year ago

We are currently leaving to the developer the database maintenance - adding columns and relationships. We have always done so and don't intent to do otherwise.

274188A commented 1 year ago

I'm not talking about adding columns. The column is already there. I have it there but the tenantId is not being saved to that column

274188A commented 1 year ago

I'm not expecting RBS to add a column.

I am expecting the code generated to save the correct tenantID value into that TenantID column.

akorchev commented 1 year ago

I think I have explained the current situation in my previous replies. We don't plan on changing the current implementation.

274188A commented 1 year ago

I see - so you cant save a tenantID in a tenantID column - I wish I knew that...

akorchev commented 1 year ago

so you cant save a tenantID in a tenantID column

I never said that. You can set the tenant id via single line of code. You just need to assign the model property to the current tenantid value.

        protected async Task FormSubmit()
        {
            try
            {
                orderDetail.TenantId = Security.User.TenantId;   // <<- set the tenantid

                await RadzenSampleService.UpdateOrderDetail(Id, orderDetail);
                DialogService.Close(orderDetail);
            }
            catch (Exception ex)
            {
                errorVisible = true;
            }
        }
274188A commented 1 year ago

OK, I'll accept that as a solution. However I have just done exactly that and the data is not filtered correctly per tenant (Global Filter). Each tenant can see each other's data despite the tenant id being set for the own record.

It's late here and I will endeavour to raise a new issue as this is a different topic and give you a sample tomorrow.

akorchev commented 1 year ago

Filtering of data by tenant isn't done automatically either. Fortunately global EF filters exist and we will add to the multitenancy help article how to filter tables.