I use Hangfire for inserting data into database. The background process has insert query in loops. Notice that starting the hundred records onwards, the performance of inserts are getting slow and decreasing in speed.
Any advise how to optimize the process? I am preparing the code to support a 20 thousands records of inserts.
Thanks
2 Answer(s)
-
0
If you use EF Core with Sql server(https://docs.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.infrastructure.relationaloptionsextension.maxbatchsize?view=efcore-3.0) to insert data by default, it is already batch.
Of course you can use the raw sql statement to batch insert data.
There are also some third-party free/charged libraries. https://github.com/borisdj/EFCore.BulkExtensions https://entityframework-extensions.net/
-
0
Have you looked at SqlBulkCopy for doing high-performance bulk inserts?
https://docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlbulkcopy?view=netframework-4.8