Wat!

EF / SQL Server writes too slow?

I was using Entity Framework Core on a project which required a large amount of writes (inserts and updates) to a SQL Server 2017 database. The operation was extremely slow, in the order of several hours/half a day. I figured out that it was due to the EF overhead for tracking changes. Setting the following boolean to false saves a lot of time, if you have to do a lot of writes:

using (var db = new MyContext())
{
db.ChangeTracker.AutoDetectChangesEnabled = false;
//Do Stuff
db.ChangeTracker.AutoDetectChangesEnabled = true;
}
Sam Afshari's Notes May 11, 2017

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.

An unhandled error has occurred. Reload 🗙