Skip to content

Latest commit

 

History

History
24 lines (20 loc) · 428 Bytes

File metadata and controls

24 lines (20 loc) · 428 Bytes

SQL005

Using 'SaveChanges' method in a loop can affect performance

Noncompliant Code Example:

var dbContext = new DbContext("test");
for (int i = 0; i < 100; i++)
{
    dbContext.Entities.Add(new Entity(i));
    s.SaveChanges();
}

Compliant Solution:

var dbContext = new DbContext("test");
for (int i = 0; i < 100; i++)
{
    dbContext.Entities.Add(new Entity(i));
}

s.SaveChanges();