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