This article is a mirror article of machine translation, please click here to jump to the original article.

View: 35943|Reply: 2

[Source] EF implements bulk database inserts, updates, and deletes

[Copy link]
Posted on 4/10/2018 5:11:30 PM | | | |
We all know that ef has poor support for batch operations, if you use ef to insert multiple pieces of data in batches or update or delete multiple statements in batches, it is a waste of time, so how to optimize ef operations for a large amount of data?

No nonsense, take a screenshot first, there is no comparison chart before and after optimization!



Statistics in the case of inserting the same 3814 pieces of data and the database is SQL Server

Before optimization:The average time was 2479 seconds
After optimization:The average time was 149 seconds

The insert code for the call is as follows:



Code before optimization:



Optimized code:

Other test code:




Optimization Scheme:

We use a third-party extension "Z.EntityFramework.Extensions", official homepage: http://entityframework-extensions.net/

Introduce:

Entity Framework: Bulk Insert, BulkSaveChanges, Bulk Update, Bulk Delete, Bulk Merge, and Bulk Sync.

Supports: SQL Server, SQL Azure, SQL Compact, Oracle, MySQL, SQLite, and PostgreSQL.

This library is not free. The trial period always ends at the end of the month.


nuget install command:







Previous:Practical Combat MySQL Database Migration Token in Windows
Next:RabbitMQ BasicQos consumer parallel processing limit
Posted on 7/20/2018 1:39:29 PM |
Z.EntityFramework.Extensions registration license
Method 1:

In the app.config or web.config file:



Method 2:



Check if the license is valid



 Landlord| Posted on 9/9/2023 8:13:54 AM |
C# inserts a large amount of data through DataTable, and it only takes 3 seconds for 500,000 data
https://www.itsvse.com/thread-3292-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com