Skip to content

Commit 590f3cc

Browse files
committed
Removed "BulkDelete" and "BulkDeleteAsync" because EF 7 supports this feature natively.
1 parent 305e438 commit 590f3cc

File tree

14 files changed

+98
-1173
lines changed

14 files changed

+98
-1173
lines changed

Readme.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ Use the [repo on GitHub](https://github.com/PawelGerr/Thinktecture.EntityFramewo
1919
* [Bulk-Insert](https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore/_wiki/wikis/Thinktecture.EntityFrameworkCore.wiki/65/Bulk-Insert)
2020
* [Bulk-Update](https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore/_wiki/wikis/Thinktecture.EntityFrameworkCore.wiki/67/Bulk-Update)
2121
* [Bulk-Upsert (Insert-or-Update)](https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore/_wiki/wikis/Thinktecture.EntityFrameworkCore.wiki/69/Bulk-Upsert-(Insert-or-Update))
22-
* [Bulk-Delete](https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore/_wiki/wikis/Thinktecture.EntityFrameworkCore.wiki/63/Bulk-Delete)
2322
* [Truncate Tables](https://dev.azure.com/pawelgerr/Thinktecture.EntityFrameworkCore/_wiki/wikis/Thinktecture.EntityFrameworkCore.wiki/64/Truncate-Tables)
2423

2524
## Features
Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,98 @@
1-
using BenchmarkDotNet.Attributes;
2-
using Microsoft.Extensions.DependencyInjection;
3-
using Thinktecture.Database;
4-
5-
namespace Thinktecture.Benchmarking;
6-
7-
[MemoryDiagnoser]
8-
public class ReferenceEqualityValueComparer : IDisposable
9-
{
10-
private BenchmarkContext? _benchmarkContext;
11-
private IServiceScope? _scope;
12-
private SqlServerBenchmarkDbContext? _sqlServerDbContext;
13-
14-
private const int _BYTES_LENGTH = 1024;
15-
16-
private int _counter;
17-
private readonly byte[] _bytesBestCase = new byte[_BYTES_LENGTH];
18-
private readonly byte[] _bytesWorstCase = new byte[_BYTES_LENGTH];
19-
20-
private List<EntityWithByteArray> _entitiesWithDefaultComparer = null!;
21-
private List<EntityWithByteArrayAndValueComparer> _entitiesWithCustomComparer = null!;
22-
23-
[GlobalSetup]
24-
public void Initialize()
25-
{
26-
_benchmarkContext = new BenchmarkContext();
27-
_scope = _benchmarkContext.RootServiceProvider.CreateScope();
28-
_sqlServerDbContext = _scope.ServiceProvider.GetRequiredService<SqlServerBenchmarkDbContext>();
29-
30-
_sqlServerDbContext.Database.EnsureDeleted();
31-
_sqlServerDbContext.Database.EnsureCreated();
32-
33-
_sqlServerDbContext.EntitiesWithByteArray.BulkDelete();
34-
_sqlServerDbContext.EntitiesWithByteArrayAndValueComparer.BulkDelete();
35-
36-
var bytes = new byte[_BYTES_LENGTH];
37-
38-
for (var i = 0; i < 10_000; i++)
39-
{
40-
var id = new Guid($"66AFED1B-92EA-4483-BF4F-{i.ToString("X").PadLeft(12, '0')}");
41-
42-
_sqlServerDbContext.EntitiesWithByteArray.Add(new EntityWithByteArray(id, bytes));
43-
_sqlServerDbContext.EntitiesWithByteArrayAndValueComparer.Add(new EntityWithByteArrayAndValueComparer(id, bytes));
44-
}
45-
46-
_sqlServerDbContext.SaveChanges();
47-
_sqlServerDbContext.ChangeTracker.Clear();
48-
}
49-
50-
[GlobalCleanup]
51-
public void Dispose()
52-
{
53-
_scope?.Dispose();
54-
_benchmarkContext?.Dispose();
55-
}
56-
57-
[IterationSetup]
58-
public void IterationSetup()
59-
{
60-
_sqlServerDbContext!.ChangeTracker.Clear();
61-
_entitiesWithDefaultComparer = _sqlServerDbContext.EntitiesWithByteArray.ToList();
62-
_entitiesWithCustomComparer = _sqlServerDbContext.EntitiesWithByteArrayAndValueComparer.ToList();
63-
64-
_bytesBestCase[0] = _bytesWorstCase[^1] = (byte)(++_counter % Byte.MaxValue);
65-
}
66-
67-
[Benchmark]
68-
public async Task Default_BestCase()
69-
{
70-
_entitiesWithDefaultComparer.ForEach(e => e.Bytes = _bytesBestCase);
71-
72-
await _sqlServerDbContext!.SaveChangesAsync();
73-
}
74-
75-
[Benchmark]
76-
public async Task Default_WorstCase()
77-
{
78-
_entitiesWithDefaultComparer.ForEach(e => e.Bytes = _bytesWorstCase);
79-
80-
await _sqlServerDbContext!.SaveChangesAsync();
81-
}
82-
83-
[Benchmark]
84-
public async Task ReferenceEquality_BestCase()
85-
{
86-
_entitiesWithCustomComparer.ForEach(e => e.Bytes = _bytesBestCase);
87-
88-
await _sqlServerDbContext!.SaveChangesAsync();
89-
}
90-
91-
[Benchmark]
92-
public async Task ReferenceEquality_WorstCase()
93-
{
94-
_entitiesWithCustomComparer.ForEach(e => e.Bytes = _bytesWorstCase);
95-
96-
await _sqlServerDbContext!.SaveChangesAsync();
97-
}
98-
}
1+
using BenchmarkDotNet.Attributes;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Thinktecture.Database;
4+
5+
namespace Thinktecture.Benchmarking;
6+
7+
[MemoryDiagnoser]
8+
public class ReferenceEqualityValueComparer : IDisposable
9+
{
10+
private BenchmarkContext? _benchmarkContext;
11+
private IServiceScope? _scope;
12+
private SqlServerBenchmarkDbContext? _sqlServerDbContext;
13+
14+
private const int _BYTES_LENGTH = 1024;
15+
16+
private int _counter;
17+
private readonly byte[] _bytesBestCase = new byte[_BYTES_LENGTH];
18+
private readonly byte[] _bytesWorstCase = new byte[_BYTES_LENGTH];
19+
20+
private List<EntityWithByteArray> _entitiesWithDefaultComparer = null!;
21+
private List<EntityWithByteArrayAndValueComparer> _entitiesWithCustomComparer = null!;
22+
23+
[GlobalSetup]
24+
public void Initialize()
25+
{
26+
_benchmarkContext = new BenchmarkContext();
27+
_scope = _benchmarkContext.RootServiceProvider.CreateScope();
28+
_sqlServerDbContext = _scope.ServiceProvider.GetRequiredService<SqlServerBenchmarkDbContext>();
29+
30+
_sqlServerDbContext.Database.EnsureDeleted();
31+
_sqlServerDbContext.Database.EnsureCreated();
32+
33+
_sqlServerDbContext.EntitiesWithByteArray.ExecuteDelete();
34+
_sqlServerDbContext.EntitiesWithByteArrayAndValueComparer.ExecuteDelete();
35+
36+
var bytes = new byte[_BYTES_LENGTH];
37+
38+
for (var i = 0; i < 10_000; i++)
39+
{
40+
var id = new Guid($"66AFED1B-92EA-4483-BF4F-{i.ToString("X").PadLeft(12, '0')}");
41+
42+
_sqlServerDbContext.EntitiesWithByteArray.Add(new EntityWithByteArray(id, bytes));
43+
_sqlServerDbContext.EntitiesWithByteArrayAndValueComparer.Add(new EntityWithByteArrayAndValueComparer(id, bytes));
44+
}
45+
46+
_sqlServerDbContext.SaveChanges();
47+
_sqlServerDbContext.ChangeTracker.Clear();
48+
}
49+
50+
[GlobalCleanup]
51+
public void Dispose()
52+
{
53+
_scope?.Dispose();
54+
_benchmarkContext?.Dispose();
55+
}
56+
57+
[IterationSetup]
58+
public void IterationSetup()
59+
{
60+
_sqlServerDbContext!.ChangeTracker.Clear();
61+
_entitiesWithDefaultComparer = _sqlServerDbContext.EntitiesWithByteArray.ToList();
62+
_entitiesWithCustomComparer = _sqlServerDbContext.EntitiesWithByteArrayAndValueComparer.ToList();
63+
64+
_bytesBestCase[0] = _bytesWorstCase[^1] = (byte)(++_counter % Byte.MaxValue);
65+
}
66+
67+
[Benchmark]
68+
public async Task Default_BestCase()
69+
{
70+
_entitiesWithDefaultComparer.ForEach(e => e.Bytes = _bytesBestCase);
71+
72+
await _sqlServerDbContext!.SaveChangesAsync();
73+
}
74+
75+
[Benchmark]
76+
public async Task Default_WorstCase()
77+
{
78+
_entitiesWithDefaultComparer.ForEach(e => e.Bytes = _bytesWorstCase);
79+
80+
await _sqlServerDbContext!.SaveChangesAsync();
81+
}
82+
83+
[Benchmark]
84+
public async Task ReferenceEquality_BestCase()
85+
{
86+
_entitiesWithCustomComparer.ForEach(e => e.Bytes = _bytesBestCase);
87+
88+
await _sqlServerDbContext!.SaveChangesAsync();
89+
}
90+
91+
[Benchmark]
92+
public async Task ReferenceEquality_WorstCase()
93+
{
94+
_entitiesWithCustomComparer.ForEach(e => e.Bytes = _bytesWorstCase);
95+
96+
await _sqlServerDbContext!.SaveChangesAsync();
97+
}
98+
}

samples/Thinktecture.EntityFrameworkCore.SqlServer.Samples/Program.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ public static async Task Main(string[] args)
3939
await DoBulkInsertOrUpdateAsync(ctx, customerId);
4040
ctx.ChangeTracker.Clear();
4141

42-
// Bulk delete
43-
await DoBulkDeleteAsync(ctx);
44-
ctx.ChangeTracker.Clear();
45-
4642
// Bulk insert into temp tables
4743
await DoBulkInsertIntoTempTableAsync(ctx, new List<Guid> { customerId });
4844
ctx.ChangeTracker.Clear();
@@ -226,18 +222,6 @@ private static async Task DoBulkInsertSpecificColumnsAsync(DemoDbContext ctx)
226222
Console.WriteLine($"Inserted customers: {insertedCustomer.Id}");
227223
}
228224

229-
private static async Task DoBulkDeleteAsync(DemoDbContext ctx)
230-
{
231-
ctx.Add(new Customer(Guid.NewGuid(), "Customer To Delete", "Test"));
232-
await ctx.SaveChangesAsync();
233-
234-
var affectedRows = await ctx.Customers
235-
.Where(c => c.FirstName == "Customer To Delete")
236-
.BulkDeleteAsync();
237-
238-
Console.WriteLine($"Number of deleted customers: {affectedRows}");
239-
}
240-
241225
private static async Task DoBulkInsertOrUpdateAsync(DemoDbContext ctx, Guid customerId)
242226
{
243227
var customer = new Customer(customerId, "First name - DoBulkInsertOrUpdateAsync", "Last name will not be updated");

samples/Thinktecture.EntityFrameworkCore.Sqlite.Samples/Program.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ public static async Task Main(string[] args)
4646
await DoBulkInsertOrUpdateAsync(ctx, customerId);
4747
ctx.ChangeTracker.Clear();
4848

49-
// Bulk delete
50-
await DoBulkDeleteAsync(ctx);
51-
ctx.ChangeTracker.Clear();
52-
5349
// LEFT JOIN
5450
await DoLeftJoinAsync(ctx);
5551
ctx.ChangeTracker.Clear();
@@ -170,16 +166,4 @@ private static async Task DoBulkUpdateAsync(DemoDbContext ctx, Guid customerId)
170166

171167
Console.WriteLine($"Updated customer: {updatedCustomer}");
172168
}
173-
174-
private static async Task DoBulkDeleteAsync(DemoDbContext ctx)
175-
{
176-
ctx.Add(new Customer(Guid.NewGuid(), "Customer To Delete", "Test"));
177-
await ctx.SaveChangesAsync();
178-
179-
var affectedRows = await ctx.Customers
180-
.Where(c => c.FirstName == "Customer To Delete")
181-
.BulkDeleteAsync();
182-
183-
Console.WriteLine($"Number of deleted customers: {affectedRows}");
184-
}
185169
}

src/Thinktecture.EntityFrameworkCore.BulkOperations/EntityFrameworkCore/Query/SqlExpressions/DeleteExpression.cs

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)