Open Closed

How use IMayHaveTenant data filter? #978

vnunes created

How do I use IMayHaveTenant?

I have my model

public class GroupCategory: Entity, IMayHaveTenant { public string MyProperty {get; set; public int? TenantID {get; set; } }

But when I use

_groupRepository.GetAllList ();

He does not return the records that do not have TenantID, ie TenantID == null

I tried to use Disable and Enable method

3 Answer(s)
  • 0
    hikalkan created

    If you disable mayhavetenant filter, then you get all data (like ... ti-tenancy). Did you logged in to the application with a tenant (what is AbpSession.TenantId value)?

  • 0
    vnunes created

    Yes, my AbpSession.TenantId has value So to get the records with null tenant and tenant logged , I do this way?

    using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant)) { //here get all register with tenantId == AbpSession.TenantId and Tenant null ? var groups = _groupRepository.GetAllList().Where(x => x.TenantId == AbpSession.TenantId); }

    Is it correct that?

    Why SaveChanges not set tenantId with IMayHaveTenant, I'm set in controller using AbpSession.TenantId, is correct?


  • 0
    hikalkan created

    I haven't understand your last question. But.. Instead of disabling, use SetFilterParameter to switch to a different tenant. Default tenant is the current tenant already (AbpSession.TenantId). So, no point to disable filter and set it to current tenant. It's the default behaviour.