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)
-
0
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:
- Save TenantId in the background job data.
- 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
-
0
Hi Hikal,
Thanks for the great answer.