Batch Delete

Introduction

Batch Delete allows you to improve EF performance by deleting multiple records in a database from a LINQ Query without loading entities.

Why Batch Delete?

For HUGE performance gains, everything is executed on the database side. To use batch delete, you will need to use a third-party library.

Example

// using Z.EntityFramework.Plus; // Don't forget to include this.

// DELETE all users inactive for 2 years
ctx.Users.Where(x => x.LastLoginDate < DateTime.Now.AddYears(-2))
.Delete();

// DELETE using a BatchSize
ctx.Users.Where(x => x.LastLoginDate < DateTime.Now.AddYears(-2))
.Delete(x => x.BatchSize = 1000);

Supported Libraries

Library Type EF Version Support Doc Features
Z.EntityFramework.Plus FREE EF5
EF6
EF Core
< 1 Day Yes Audit
Batch Delete
Batch Update
Cache
Deferred Query
Filter
Future
Include Filter
Include Optimized

Unsuported Libraries

Use these libraries at your risk!

Library Type EF Version Support Doc Features
EFUtilities FREE EF5
EF6
No No Bulk Insert
Batch Delete
Batch Update
Include Optimized
EntityFramework.Extended FREE EF5
EF6
No Yes Audit
Batch Delete
Batch Update
Cache
Future