Search code examples
c#sql-serverdatabaseentity-frameworksql-scripts

Frequent saving database efficient with millions of entries?


I am trying to insert a ton of data into a SQL server database and my question is, how often i should save when millions of entries are going to be inserted there. Is it efficient to save it after e.g. 10.000 inserts or after 1.000.000 inserts? Are there any go-to values? I am using C# Entity Framework to populate the server with the data, so i am using a DBContext class which handles the CRUD and saving.


Solution

  • I am using C# Entity Framework to populate the server with the data

    Your problems start here. It is not suitable for this. WRONG TOOL. I like Entity Frameowrk, but it is an ORM, not a bulk loading tool.

    I generally use SqlBulkLoader class to load up to 65k records to a temporary table (in seconds, but beware, you pretty much must use a temporary table) which I the ncopy to the final table in one command / transaction.

    Handling 4-5 threads parallel with full speed.

    Entity Framework will take hours for a million rows, regardless how you turn it. Just the wrong tool.