SQL Entity Framework Add to Database Question

Joined
Dec 24, 2019
Messages
10
Location
Florida, USA
Programming Experience
Beginner
Hello, I am using c# and entity frarmework to save data to a database...there will be over 30,000 objects to be saved to the database.....my question is -

is it better to save a single object over and over again 1 at a time or is it more efficient to save a List<Object> with .Range?

thank you
 
Is the saving of these 30,000 objects a one time seeding of the database? Or is this a periodic operation (weekly, monthly, yearly) where you need to load 30,000 new items in a big batch? If it is a one time load, the efficiency doesn't really matter that much since it's a one time cost.
 
Also relevant:
 
See that SO post I linked above. Lots of good info there since I am very anti-EF, and anti-SQL, as well.

My personal recommendation is to do a straight on SqlBulkCopy if you can, and just bypass EF completely. If you must absolutely use EF, then that common wisdom is to do batches of about 500 objects and call SaveChanges() within the lifetime of a DbContext, dispose of that context. Lather, rinse, repeat until you finish uploading your new data.
 
Back
Top Bottom