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

How use IMayHaveTenant data filter? #978


User avatar
0
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)
  • User Avatar
    0
    hikalkan created
    Support Team

    If you disable mayhavetenant filter, then you get all data (like <a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Zero/User-Management#multi-tenancy">http://www.aspnetboilerplate.com/Pages/ ... ti-tenancy</a>). Did you logged in to the application with a tenant (what is AbpSession.TenantId value)?

  • User Avatar
    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?

    Thanks

  • User Avatar
    0
    hikalkan created
    Support Team

    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.