AspNet Zero 10.1 Angular - .Net Core
Hello!
Please explain why you will switch to the host in the method GetCurrentTenant of AppServiceBase class:
protected virtual Task<Tenant> GetCurrentTenantAsync() { using (CurrentUnitOfWork.SetTenantId(null)) { return TenantManager.GetByIdAsync(AbpSession.GetTenantId()); } }
Best regards!
4 Answer(s)
-
0
Hi @tankods
Because, there is an active multi tenancy filter which filters entities which implement IMayHaveTenant or IMustHaveTenant interface according the value of current TenantId in AbpSession. If we don't switch host side, the query will return 0 records.
You can read more here https://aspnetboilerplate.com/Pages/Documents/Data-Filters
-
0
Hi, thanks for your answer, but tenant entity don't impliment IMayHaveTenant or IMustHaveTenant interface, and if i correctly understood filter, CurrentUnitOfWork.SetTenantId(null) make what we select only entities of host.
Best regards.
-
1
Hi @tankods
Correct. But, for Tenant entity, it is stored in Host database. AspNet Zero allows Tenants to use separate databases. So, when this code is accessed from a Tenant context, using
CurrentUnitOfWork.SetTenantId(null)
will allow app to access Host database. If we don't use it, there will be a problem when using this code from a Tenant context with a separate database. -
0
Thank you, forgot about separate databases feature.