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

IMayHaveTenant question #3028


User avatar
0
dmali created

Hi,

in our system we would like to share one entity between host and tenant like this:

  • host can add new entities and they are visible to all tenants
  • host can see ony entities added by him (tenant id = null)
  • tenant can see enities added by him or host

Our entity implements FullAuditedEntity, IMayHaveTenant interfaces, but for some reason tenants are not able to see enitites added by host.

basically we would like to have same funcinality like you did with application languages.

Could you please tell us what we are doing wrong?

Kind reagards


4 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    This is not possible by default in the design of ABP. We are caching host languages and merging them with current tenant's languages when you call languages app service.

    In your case, you first need to switch to host context to get host entities. Then you need to get entities for current tenant and merge two list before returning data to client, see <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants">https://aspnetboilerplate.com/Pages/Doc ... nd-tenants</a>.

  • User Avatar
    0
    dmali created

    Hi,

    we solve it like this:

    using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MustHaveTenant, AbpDataFilters.MayHaveTenant))
    {             
    	var entities = _entityRepository
    		.GetAll()
    		.WhereIf(AbpSession.TenantId.HasValue, c => c.TenantId == AbpSession.TenantId.Value || c.TenantId == null) // tenant
    		.WhereIf(!AbpSession.TenantId.HasValue, c => c.TenantId == null); // host
    
    		...
    }
    

    It's working as we want, but we are not sure if it will work in multi database environment.

    what's your opinion?

    Best regards

  • User Avatar
    0
    bilalhaidar created

    Hi, I read in the documentation that it is recommended to make use of SetTenantId instead of DisableFilter.

    Regards Bilal

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In multi database approach, this code does not work when tenant and host databases are seperated. Instead of doing this, I suggest you to execute two queries one for host and one for current tenant using SetTenantId.

    Thanks.