public void Execute(IJobExecutionContext context) { Log.LogInfoMessage("[Enter] auditing"); var HistoricalDateLimit = AuditDate.AddDays(-1 * int.Parse(ConfigurationManager.AppSettings["NumberOfDaysInThePast"])); using (PCSDataContext PCSContext = new PCSDataContext()) { foreach (PCSAudit audit in PCSContext.Audits.Get(x => x.TransAuditStatus == (int)AuditStatus.ValidatedIncorrect) .Where(x => x.AuditDate >= HistoricalDateLimit) .OrderBy(x => x.AuditDate) .ThenBy(x => x.AuditHour) .Take(int.Parse(ConfigurationManager.AppSettings["AuditChunkSize_Trans"]))) { PCSAudit audit_ = audit; // avoid closure issues DateTime StartDate = audit_.AuditDate.Date; DateTime EndDate = audit_.AuditDate.Date.AddDays(1); var TransactionCount = PCSContext.Transactions.Count(x => x.TransDate.Hour == audit_.AuditHour && x.TransDate > StartDate && x.TransDate < EndDate && x.Session.Lane.LaneGUID == audit_.LaneGuid); AuditTransactions(TransactionCount, audit, PCSContext); } PCSContext.Save(); } Log.LogInfoMessage("[Exit] auditing"); }