Hi there, Im using IRepository<OrganizationUnit, long> in a schedule background job with Quartz, but the getAll() method is returning empty, even when I have organization units in my database. The repository works fine inside managers and services.
This is part of my code:
public class MyBackgroundJob : JobBase, ITransientDependency
{
private readonly IRepository<OrganizationUnit, long> _organizationUnitRepository;
public MyBackgroundJob(IRepository<OrganizationUnit, long> organizationUnitRepository)
{
_organizationUnitRepository = organizationUnitRepository;
}
public override void Execute(IJobExecutionContext context)
{
using (var unitOfWork = UnitOfWorkManager.Begin())
{
IQueryable<OrganizationUnit> organizationUnits = _organizationUnitRepository.GetAll();
.....
At this point organizationUnits its allways empty.
What can I be missing here?
Thanks in advance.
2 Answer(s)
-
0
Hi,
You query will be executed for host records with TenantId=null. Maybe that is why you don't get any records.
In background jobs, you need to explicitly set tenantId you wnat to operate on. See <a class="postlink" href="https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants">https://aspnetboilerplate.com/Pages/Doc ... nd-tenants</a>.
Thanks.
-
0
Thanks, problem solved.