Entity Framework 5 Batch increase and deletion efficiency optimization

Source: Internet
Author: User

The slowest way to change the volume and deletion of data is to commit one transaction at a time.

The following is an optimization test for adding and deleting operations

The same 300-piece data

Bulk new commits only one transaction

Spents: 10673.5444ms

Batch add only commits once transaction and puts context. Configuration.autodetectchangesenabled = False  

Spents: 5284.5425ms

Bulk modification commits only one transaction

Spents: 3472.8314ms

Batch modification commits only one transaction and the context. Configuration.autodetectchangesenabled = False  

Spents: 1993.7855ms

Bulk Delete commits only one transaction

Spents: 5961.3264ms

Bulk Delete commits the transaction only once and puts the context. Configuration.autodetectchangesenabled = False  

Spents: 1346.8273ms

Delete There is a special reminder that my deletion method uses the alias delete, instead of first detecting data from the database and then deleting it.

Comparison of two methods of deletion

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 increase in efficiency is obvious.

Entity Framework 5 Batch increase and deletion efficiency optimization

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.