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

Empty Repository extended non-abstract entity from periodicbackgroundworker #5777


User avatar
0
rvanwoezik created

HI, I have an clinic entity which is an extension of OrganizationUnit

public class Clinic : OrganizationUnit {...} All works fine, but when i call this repository from a periodicbackgroundworker this repository is empty! `protected override void DoWork() { var utcNow = Clock.Now.ToUniversalTime();

        var clinics = _clinicRepository.GetAllList();
        `
        when i call other normal repositories there not empty.
        
        Please advice
        

8 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Did you insert any?

  • User Avatar
    0
    rvanwoezik created

    :-) ofcourse

  • User Avatar
    0
    aaron created
    Support Team

    In host?

  • User Avatar
    0
    rvanwoezik created

    I have about 75 clinics in my database, clinic is an extension of organizationunit. i have added Address, Phone etc. All crud operations work from application layer.

    ` public class ClinicClosedCheckWorker : PeriodicBackgroundWorkerBase, ISingletonDependency { private const int CheckPeriodAsMilliseconds = 1 * 60 * 60 * 24 * 1000; //1 day

        private readonly IRepository<Clinic, long> _clinicRepository;
        private readonly OrganizationUnitManager _organizationUnitManager;
    
    
        public ClinicClosedCheckWorker(
            AbpTimer timer,
            IRepository<Clinic, long> clinicRepository,
            OrganizationUnitManager organizationUnitManager
            ) : base(timer)
        {
            _clinicRepository = clinicRepository;
            _organizationUnitManager = organizationUnitManager;
            Timer.Period = CheckPeriodAsMilliseconds;
            Timer.RunOnStart = true;
    
            LocalizationSourceName = PhoogleConsts.LocalizationSourceName;
    
        }
    
        protected override void DoWork()
        {
            var utcNow = Clock.Now.ToUniversalTime();
    
            var closedClinics = _clinicRepository.GetAllList(
                clinic => clinic.ClosingDate != null);
                
            
            foreach (var clinic in closedClinics)
            {
                try
                {
                    if (clinic.ClosingDate <= utcNow)
                    {
                        _organizationUnitManager.Delete(clinic.Id);
                    }
    
                }
                catch (Exception exception)
                {
                    Logger.Error($"Clinic is gesloten maar kan niet worden verwijderd");
                    Logger.Error(exception.Message, exception);
                }
                
            }
    
        }
    }
    

    `

  • User Avatar
    0
    aaron created
    Support Team

    Did you insert any in host?

  • User Avatar
    0
    rvanwoezik created

    I'm sorry, but i don't know what you mean? You mean live database?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @rvanwoezik

    In background job, _clinicRepository.GetAllList will return the clinics of the Host. If you want to retrieve clinics of a specific tenant, you need to switch to the tenant context, https://aspnetboilerplate.com/Pages/Documents/Multi-Tenancy#switching-between-host-and-tenants.

    If you want to retrieve all records, you can disable MayHaveTenant filter https://aspnetboilerplate.com/Pages/Documents/Data-Filters#disable-filters but it will fail if you are using at least one separate database for a tenant.

  • User Avatar
    0
    rvanwoezik created

    Thnx! you are the best!