Base solution for your next web application
Open Closed

Background job passing null tenantId when making calls to repositories - how can I change it beforehand? #8875


User avatar
0
adudley created

When I'm making calls to a respository from a background job, the tenantId is always null. I've tried including the tenantId in the where clause

e.g. _roleRepository.GetAll().Where(r => r.TenantId == args.TenantId);

My understanding though, is that this where is considered after abp has already filtered the data on the tenantId. Therefore, it will never find anything as all the data it's searching will have a tenantId of null.

Is there a way I can set the tenantId the repositories are using within the background job class itself?

Thanks in advance.


2 Answer(s)
  • User Avatar
    0
    smry created

    is there anything in AbpSession.TenantId variable?

  • User Avatar
    1
    adudley created

    I found the solution. Thanks though :)

    For anyone else having this issue, I recommend: https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy

    The section "Switching Between Hosts and Tenants"