I have a simple routine to add records to a database using the entity framework. I wanted to make this
perform as fast as possible and wanted to make sure I am doing thing correctly.
To add multiple records to a table should I be creating a new instance of the record object each time.
PidTable pid_table = new PidTable(); so for 100 records a 100 object creations?
Also can I assume that the context.SaveChanges will buffer up all the changes in memory and
write them in one hit. So it is more efficient to have that at the end then within the loop
Also in regards to SaveChanges() I assume that the more records that are changed the more memory is used. Is there a limit to this is is it governed by the amount of free memory.
Additionally can I reclaim the memory back from SaveChanges() after the context is disposed or do I need to wait for .NET garbage collection.
Any advice greatly appreciated.
private void fnAdd_100_Records()
CarDBEntities context = new CarDBEntities();
for (counter = 1; counter <= 100; counter++)
PidTable pid_table = new PidTable();
pid_table.ID = counter.ToString();
pid_table.PID1 = (decimal)counter;