I'm puzzled as to why this code is not working, it should save changes to database after the loops but when I place the SaveChanges method inside the loop, it saves the record into the database but outside it doesn't save anything? it's about only 300 ~ 1000 records
    static bool lisReady = false;
    static bool sacclReady = false;
    static void Main(string[] args)
    {
        Logger("Starting services");
        ConnectDBLis().Wait();
        ConnectDBSaccl().Wait();
        Thread.Sleep(1000);
        if (lisReady & sacclReady){
            //start
            Logger("Services ready");
            StartExport().Wait();
        }
    }
    static async Task<bool> StartExport()
        {
            lis lisdb = new lis();
            nrlsaccl saccldb = new nrlsaccl();
            var getTestOrders = await lisdb.test_orders.ToListAsync();
            Logger("Services starting");
            foreach (var tO in getTestOrders.Where(x => x.entry_datetime.Value.Year == 2016))
            {
                foreach (var tr in tO.test_results)
                {
                    foreach (var tL in tr.test_result_logs)
                    {
                        results_availability postResults = new results_availability
                        { 
                          first_name = tO.patient_orders.patient.first_name,
                          middle_name = tO.patient_orders.patient.middle_name,
                          last_name = tO.patient_orders.patient.last_name,
                          birthdate = tO.patient_orders.patient.birthdate,
                        };
                        if (postResults.id == 0)
                        {
                            saccldb.results_availability.Add(postResults);
                        }
                        else
                        {
                            saccldb.Entry(postResults).State = EntityState.Modified;
                        }
                    }
                }
            }
            await saccldb.SaveChangesAsync();
            return true;
        }
Edit:
So i limit the records to 100 and the save changes works, 3000 records at instant does not work, any solutions?
 
     
     
    