.NET Bulk Operations Bulk Delete

Description

The BulkDelete method let 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)

Try it (Entity)

Performance View

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

Try it (DataTable)

Try it (Entity)

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)

Try it (Entity)

Bulk Delete with options

The options parameter let you use a lambda expression to customize the way entities are deleted.

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

Try it (DataTable)

Try it (Entity)

Real Life Scenarios

Delete with custom key

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

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

Try it (DataTable)

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

Try it (Entity)

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. Try it Try it
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:

In this Page