Lets assume that we are writing a data import app and we will be adding lots of similar entities to the database, let's say 1 million. We create objects in code and then we write them into the database in batches.
Which case is better:
- As we create objects, we use
dbcontext.Add(object);
at the end of the creation. - As we create objects, we add them to a list
objectsToSave.Add(object);
and after we have 1000 objects in the list, we calldbcontext.AddRange(objectsToSave);
In both cases we call dbcontext.SaveChanges();
after 1000 items are queued in dbcontext to be inserted.
Is there going to be a considerable difference in performance between the two?