Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Unable to set multitenancy off on template 6.9.1 #6824


User avatar
0
commondesk created

Hello,

I have a problem with multitenancy. We only support single tentant on our website so we always disable MultiTenancy

Yesterday I upgraded our website to template 6.9.1, as i was merging our changes and testing i got to the file project Project Consts file where this line is defined

public const bool MultiTenancyEnabled = true;

And i set it to false, after this i created the database and started the backend app

Then i get an error on DefaultSettingsCreator.Create()

var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == MultiTenancy.Tenant.DefaultTenantName); tenantId = defaultTenant.Id;

Here, defaultTenant is always null so the next line 'defaultTenant.Id' throws a null reference exception

Since this happens the first time we load the app, the database default data is never inserted and we can't get a working system

If i set MultiTenancyEnabled to true, then these line is skipped and everything works

'var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == MultiTenancy.Tenant.DefaultTenantName);'

NOTE:

I changed the app to use Mysql, then generated new migrations and removed the sql server migrations, this is the only change we have but i'm not sure if having a different Database backend is related to this issue

Any help appreciated as we have not found a way to initialize the first time while having MultiTenancy disabled

Thanks


9 Answer(s)
  • User Avatar
    0
    nallejacobsson created

    We have the same problem with 6.9.1. I solved it by starting the first time with MultiTenancy enabled, then I disabled it.

    Also see this:

    https://support.aspnetzero.com/QA/Questions/6778

  • User Avatar
    0
    smastro created

    The workaround suggested above works but all Unit Tests still fail when you set MultiTenancyEnabled = false.

    I added a few more details on #6857

  • User Avatar
    0
    ismcagdas created
    Support Team
  • User Avatar
    0
    smastro created

    Thanks!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Just to remind you, this issue has been fixed.

  • User Avatar
    0
    commondesk created

    How has this been fixed?

    What im doing to fix it is:

    1 - Compiling the app with multi tennant support 2 - Running the app 3 - Compiling the app WITHOUT multi tennant support 4 - Running the app

    This is not a viable solution for system deployed via continous intergration.

  • User Avatar
    0
    commondesk created

    I see you're saying this is the fix

    https://github.com/aspnetzero/aspnet-zero-core/commit/c4fa5baeb2974c62937fa0be93f6b1439ca4e177

    ??

  • User Avatar
    0
    maliming created
    Support Team

    Yes, When disabling multi-tenancy, there is a problem if you use a brand new database(throws a null reference exception). Because there is no tenant information at this time.

    So we use DefaultTenantId, which is the default value when multi-tenancy is disabled.

  • User Avatar
    0
    maliming created
    Support Team

    hi @silpoint

    7.0 will be fixed. The code fixed is very simple.

    https://aspnetzero.com/LicenseManagement

    You can invite anyone to become a member of the ASP.NET Zero organization using their GitHub username. And they can access the ASP.NET Zero private GitHub repositories. Your license plan allows you to add up to 3 users. Right after you add a GitHub user, the user will receive an invitation email. If there is problem receiving the invitation email, alternatively user can visit github.com/orgs/aspnetzero page and accept the invitation.