Improve Entity Framework Performance

Introduction

Is it Entity Framework as slow as some people report it? Yes and no.

Entity Framework offers great advantage over other ORM, and it’s in fact pretty fast.

Problem

The problem’s too easy to fall into one or another Entity Framework performance pitfall.

Soon or later, we all make some mistakes which may impact the application performance severely.

Performance Cheat Sheet

Problem Solution
Add
  • Use AddRange
  • Disable AutoDetectChanges
  • Add in Batches
Change Tracker
  • Track Less Entities
DetectChanges
  • Disable AutoDetectChanges
  • SaveChanges in Batches
Eager Loading
  • Use AsNoTracking
  • Use EF+ Caching
  • Use EF+ Query Future
Lazy Loading
  • Use Eager Loading
Include
  • Split in multiple Include
  • Use EF+ IncludeFilter
  • Use EF+ IncludeOptimized
Insert
  • Use EFE BulkInsert
Query
  • Use AsNoTracking
  • Use EF+ Caching
  • Use EF+ Query Future
SaveChanges
  • Use EFE Bulk Operations
  • Use EFE BulkSaveChanges

Recommendation

Have you read all theses articles? Great! Read them all again a second and a third time if necessary.

These articles are still under development. We recommend you to subscribe to our newsletter to stay updated.