Skip to content

Commit f9fa66f

Browse files
Update bulk-delete.md
1 parent 933f35a commit f9fa66f

File tree

1 file changed

+100
-22
lines changed

1 file changed

+100
-22
lines changed
Lines changed: 100 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,116 @@
11
# Bulk Delete
22

3-
## Bulk Delete
4-
Execute a DELETE operation.
3+
## Description
54

6-
### Example - Bulk Insert
7-
```csharp
8-
var dt = new DataTable();
9-
// ...seed...
5+
The `BulkDelete` method let you delete a large number of entities in your database.
106

11-
var bulk = new BulkOperation(connection);
7+
```csharp
8+
// Easy to use
9+
bulk.DestinationTableName = "Customers";
10+
bulk.BulkDelete(customers);
1211

1312
// Easy to customize
14-
bulk.BatchSize = 1000;
15-
16-
// Easy to use
17-
bulk.BulkDelete(dt);
13+
bulk.DestinationTableName = "Customers";
14+
bulk.BatchSize = 100;
15+
bulk.BulkDelete(customers);
1816
```
17+
[Try it (DataTable)](https://dotnetfiddle.net/XgKaqz)
18+
19+
[Try it (Entity)](https://dotnetfiddle.net/O3jY32)
20+
21+
22+
### Performance View
23+
24+
| Operations | 1,000 Entities | 2,000 Entities | 5,000 Entities |
25+
| :-------------- | -------------: | -------------: | -------------: |
26+
| BulkDelete | 50 ms | 55 ms | 75 ms |
27+
28+
29+
[Try it (DataTable)](https://dotnetfiddle.net/TknFpT)
30+
31+
[Try it (Entity)](https://dotnetfiddle.net/CzSZx8)
32+
33+
> HINT: A lot of factors might affect the benchmark time such as index, column type, latency, throttling, etc.
34+
35+
### Scenarios
36+
The `BulkDelete` method is **fast** but also **flexible** to let you handle various scenarios such as:
37+
38+
- [Delete with custom key](#delete-with-custom-key)
39+
- [More scenarios](#more-scenarios)
40+
41+
### Advantages
42+
- Easy to use
43+
- Flexible
44+
- Increase performance
45+
- Increase application responsiveness
46+
47+
## Getting Started
48+
49+
### Bulk Delete
50+
The `BulkDelete` and `BulkDeleteAync` methods your let you delete a large number of entities in your database.
1951

20-
### Example - Bulk Insert Generic
2152
```csharp
22-
var list = new List<Customer>();
23-
// ...seed...
53+
bulk.BulkDelete(customers);
2454

25-
var bulk = new BulkOperation<Customer>(connection);
55+
bulk.BulkDeleteAsync(customers, cancellationToken);
56+
```
57+
[Try it (DataTable)](https://dotnetfiddle.net/Ss93gv)
2658

27-
// Easy to customize
28-
bulk.BatchSize = 1000;
59+
[Try it (Entity)](https://dotnetfiddle.net/p8dt0G)
2960

30-
// Easy to use
61+
### Bulk Delete with options
62+
The `options` parameter let you use a lambda expression to customize the way entities are deleted.
63+
64+
```csharp
65+
bulk.BatchSize = 100;
3166
bulk.BulkDelete(customers);
3267
```
68+
[Try it (DataTable)](https://dotnetfiddle.net/NQlmua)
69+
70+
[Try it (Entity)](https://dotnetfiddle.net/KLFfCw)
71+
72+
## Real Life Scenarios
73+
74+
### Delete with custom key
75+
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.
76+
77+
```csharp
78+
bulk.AutoMapKeyName = "Code";
79+
bulk.BulkDelete(dtCustomers.AsEnumerable().Take(2));
80+
```
81+
[Try it (DataTable)](https://dotnetfiddle.net/XKUBto)
82+
83+
```csharp
84+
bulk.AutoMapKeyExpression = customer => customer.Code;
85+
bulk.BulkDelete(customers.Take(2));
86+
```
87+
[Try it (Entity)](https://dotnetfiddle.net/yc5tqc)
88+
89+
### More scenarios
90+
Hundred of scenarios has been solved and are now supported.
91+
92+
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:
93+
info@zzzprojects.com
94+
95+
## Documentation
96+
97+
### BulkDelete
98+
99+
###### Methods
100+
101+
| Name | Description | Example (DataTable) | Example (Entity) |
102+
| :--- | :---------- | :------ | :------ |
103+
| `BulkDelete<T>(items)` | Bulk delete entities in your database. | [Try it (Entity)](https://dotnetfiddle.net/a6Txdy) | [Try it (DataTable)](https://dotnetfiddle.net/srOJJ8)
104+
| `BulkDeleteAsync<T>(items)` | Bulk delete entities asynchronously in your database. | | |
105+
| `BulkDeleteAsync<T>(items, cancellationToken)` | Bulk delete entities asynchronously in your database. | | |
33106

34-
### Performance Benchmarks
107+
###### Options
108+
More options can be found here:
35109

36-
| Operations | 1,000 Rows | 10,000 Rows | 100,000 Rows | 1,000,000 Rows |
37-
| :-------------- | -------------: | -------------: | -------------: | -------------: |
38-
| BulkDelete | 45 ms | 70 ms | 625 ms | 6,800 ms |
110+
- [Audit](https://bulk-operations.net/audit)
111+
- [Batch](https://bulk-operations.net/batch)
112+
- [Execute Event](https://bulk-operations.net/execute-event)
113+
- [Log](https://bulk-operations.net/log)
114+
- [Temporary Table](https://bulk-operations.net/temporary-table)
115+
- [Transient Error](https://bulk-operations.net/transient-error)
116+
- [SQL Server](https://bulk-operations.net/sql-server)

0 commit comments

Comments
 (0)