Entity Framework Performance Tip: Disable Automatic Change Detection for Bulk Operations

A dev on the EF team says some stuff here about Entity Framework’s automatic change detection that I think we might find valuable:

When you need to manipulate many entities … the advice is to switch off AutoDetectChanges while you, for example, do all your Adds, and then switch it back on again afterwards.

You can turn off automatic change detection at the context level like this:

myContext.Configuration.AutoDetectChangesEnabled = false;

I haven’t looked at the performance improvements you get from this, but this post makes me think the performance would go from quadratic to linear. That’s a big boost.

(Here’s another well written post on the matter.)