Rule Definition
When doing bulk update/create you need to disabled EF's changetracking. This can easily be done by disabled AutoDetectChanges. Once you're done, you need to turn Changetracking back on otherwise you might have some unwanted behavior.
Remediation
Esnure you disable the changetracking option when doing bulk changes.
Violation Code Sample
foreach (var newDay in daysOf2019)
dayRepo.Add(newDay); // ⚠️ VIOLATION: Each Add will be saved in database
Fixed Code Sample
Configuration.AutoDetectChangesEnabled = false; // ✓ FIXED
foreach (var newDay in daysOf2019)
dayRepo.Add(newDay);
ChangeTracker.DetectChanges();
SaveChanges();
Reference
https://www.entityframeworktutorial.net/efcore/changetracker-in-ef-core.aspx
Related Technologies
Technical Criterion
Efficiency - SQL and Data Handling Performance
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.