Code
foreach (var item in _context.Duiven.
.Include(p => p.Duivenmelker.VoedselInstelling)
.Include(p => p.VoedselHistoriek)
.Include(p => p.Duivenmelker.Personeel)
.Include("Ziektes.DuifZiekte")
.ToList() // 25.000)
{
item.FoodHistory();
item.HealthSimulation();
item.DiseaseSimulation(diseaseTypes);
item.CureSimulation(_context);
item.DeathSimulation();
item.Feed();
}
_context.SaveChanges()
Problem
The above code loops through aprox. 25000 items. It updates all kinds of stuff on these objects (This process takes about 10 minutes) The problem lies in saving all these changes to the database, which takes almost 2 hours.
It updates (sql) each change one by one probably? (This is sql azure) The process also includes delete 25000 records & inserting 25000 new ones (4 ints)
I have reduced the calls to the database by including a lot that is needed. But I discovered that it's not the process but the saving that takes so long :S
Questions
Is there a difference in performce between [updating all values from a record] and [deleting current & inserting new]?
How could I improve saving this to the database? Like in 10 minutes instead of 160m ?