CRITICAL
Rule Definition
When updating or inserting thousands of records, EF's change tracking and individual update statements become a bottleneck.
Slow performance due to individual SQL statements
High memory usage
Remediation
Use frameworks like EFCore.BulkExtensions to issue efficient bulk operations.
Use BulkUpdate() or ExecuteUpdate() in EF Core 7+
Violation Code Sample
foreach (var entity in largeList)
{
entity.Status = "Processed";
dbContext.Update(entity); // ⚠️ VIOLATION
}
dbContext.SaveChanges(); // inefficient for thousands of rows
Fixed Code Sample
foreach (var entity in largeList)
{
entity.Status = "Processed";
}
dbContext.BulkUpdate(largeList); // requires EFCore.BulkExtensions
Reference
https://github.com/borisdj/EFCore.BulkExtensions
Related Technologies
Technical Criterion
CWE-1050 - Excessive Platform Resource Consumption within a Loop [Base]
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.