Sunday, May 22, 2016

Improving performance in working with EF



I stumbled across a SO post about performance, where the main hindrance was Entity Framwork/DB operations.

Here's a summary of the suggested approaches for performance improvement:

  •  Using Dapper or raw ADO.NET components.
  • Disabling EF change auto detection and validation on save flags.
  • Using BulkInsert
  • Instead of adding new entities inside a loop, collect all the entity objects to be added into a collection - and one you are finished issue a single [entity].AddRange(collection) to push all the new entities into the EF object (and afterwards performing a SaveChanges). It is stated that this is performance-wiser.
I myself was familiar with the 2nd and 3rd suggestions. Should give Dapper and AddRange a try.

Some performance comparison tests for the above can be found in the web, here is a nicely presented one.

See also Performance considerations for EF 4, 5 and 6.

No comments:

Post a Comment