Entity framework 5 batch addition, deletion, modification efficiency optimization, entityframework

Source: Internet
Author: User

Entity framework 5 batch addition, deletion, modification efficiency optimization, entityframework

The slowest time for batch addition, deletion, and modification of data is to commit a transaction after one operation.

The following is an optimization test for the addition, deletion, and modification operations:

Same 300 data records

Batch Add a transaction only submitted once

Time in use: 10673.5444 ms

Batch Add a transaction only submitted once and set context. Configuration. AutoDetectChangesEnabled = false

Time in use: 5284.5425 ms

 

Submit transactions only once for batch Modification

Time in use: 3472.8314 ms

Submit the transaction only once for batch modification and set context. Configuration. AutoDetectChangesEnabled = false

Time in use: 1993.7855 ms

 

Batch deletion only submits transactions once

Time in use: 5961.3264 ms

Batch Delete only commit transactions once and set context. Configuration. AutoDetectChangesEnabled = false

Time in use: 1346.8273 ms

A special reminder is that my deletion method uses a replacement to delete data, instead of checking data from the database before deleting it.

Comparison of the two deletion Methods

Slow

Var stu = context. Students. SingleOrDefault (s => s. StudentNo = 23230 );
Context. Students. Remove (stu );
Context. SaveChanges ();

Fast

Var stu = new Student {StudentNo = 23230 };
Context. Students. Attach (stu );
Context. Students. Remove (stu );
Context. SaveChanges ();

 

Obviously, the efficiency improvement is obvious.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.