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

How to Auto set TenantId for BackgroundJob Entity Creation #1524


User avatar
0
feliw created

Hi,

Currently we have a background job which calling a method to do a calculation and performing entity (IMustHaveTenant) creation. When I call the save changes I got an error of TenantId must be set, is there a way to auto set the tenant id as the jobStore ? Right now for each entity creation I need to set the TenantId manually.

Thanks, any advice or direction will be a great help.


2 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    As you know, background jobs are executed out of http context, independent from requests. So, we can not know which tenant you want to use in current operation. So, you should do that:

    1. Save TenantId in the background job data.
    2. Use UnitOfWork.SetTenantId to set the tenantid (<a class="postlink" href="http://www.aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants">http://www.aspnetboilerplate.com/Pages/ ... nd-tenants</a>).

    Then all your operations in this UOW will be performed for the given .tenant

  • User Avatar
    0
    feliw created

    Hi Hikal,

    Thanks for the great answer.