.NET Bulk Operations Bulk Delete

Description

The BulkDelete method lets you delete a large number of entities in your database.

// Easy to use
bulk.DestinationTableName = "Customers";
bulk.BulkDelete(customers);

// Easy to customize
bulk.DestinationTableName = "Customers";
bulk.BatchSize = 100;
bulk.BulkDelete(customers);

Try it (DataTable): .NET Core | .NET Framework

Try it (Entity): .NET Core | .NET Framework

Performance View

Operations 1,000 Entities 2,000 Entities 5,000 Entities
BulkDelete 50 ms 55 ms 75 ms

Try it (DataTable): .NET Core | .NET Framework

Try it (Entity): .NET Core | .NET Framework

HINT:

A lot of factors might affect the benchmark time such as index, column type, latency, throttling, etc.

Scenarios

The BulkDelete method is fast but also flexible to let you handle various scenarios such as:

Advantages

  • Easy to use
  • Flexible
  • Increase performance
  • Increase application responsiveness

Getting Started

Bulk Delete

The BulkDelete and BulkDeleteAync methods your let you delete a large number of entities in your database.

bulk.BulkDelete(customers);

bulk.BulkDeleteAsync(customers, cancellationToken);

Try it (DataTable): .NET Core | .NET Framework

Try it (Entity): .NET Core | .NET Framework

Bulk Delete with options

The options parameter lets you usehttps://dotnetfiddle.net/J86vbg a lambda expression to customize the way entities are deleted.

bulk.BatchSize = 100;
bulk.BulkDelete(customers);

Try it (DataTable): .NET Core | .NET Framework

Try it (Entity): .NET Core | .NET Framework

Real-Life Scenarios

Delete with custom key

You want to delete entities, but you don't have the primary key. The ColumnPrimaryKeyExpression lets you use as a key any property or combination of properties.

bulk.AutoMapKeyName = "Code";
bulk.BulkDelete(dtCustomers.AsEnumerable().Take(2));

Try it (DataTable): .NET Core | .NET Framework

bulk.AutoMapKeyExpression = customer => customer.Code;
bulk.BulkDelete(customers.Take(2));

Try it (Entity): .NET Core | .NET Framework

More scenarios

Hundred of scenarios has been solved and are now supported.

The best way to ask for a special request or to find out if a solution for your scenario already exists is by contacting us: info@zzzprojects.com

Documentation

BulkDelete

Methods
Name Description Example (DataTable) Example (Entity)
BulkDelete<T>(items) Bulk delete entities in your database. .NET Core / .NET Framework .NET Core / .NET Framework
BulkDeleteAsync<T>(items) Bulk delete entities asynchronously in your database.
BulkDeleteAsync<T>(items, cancellationToken) Bulk delete entities asynchronously in your database.
Options

More options can be found here:



Contents