From 4407104249617424ca31aeccf3dc6f022623b9b7 Mon Sep 17 00:00:00 2001 From: Haik Date: Thu, 11 Apr 2024 17:28:17 +0400 Subject: [PATCH 1/2] update demo --- .../Dtos/BulkBenchmarkResponse.cs | 3 +- test/PandaNuGet.Demo/PandaNuGet.Demo.csproj | 1 + test/PandaNuGet.Demo/Program.cs | 12 ++++-- .../Services/BulkInsertService.cs | 37 +++++++++++++++++++ test/PandaNuGet.Demo/appsettings.json | 4 +- 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/test/PandaNuGet.Demo/Dtos/BulkBenchmarkResponse.cs b/test/PandaNuGet.Demo/Dtos/BulkBenchmarkResponse.cs index 812b765..cc12e26 100644 --- a/test/PandaNuGet.Demo/Dtos/BulkBenchmarkResponse.cs +++ b/test/PandaNuGet.Demo/Dtos/BulkBenchmarkResponse.cs @@ -9,5 +9,6 @@ public enum BenchmarkMethod { EFCore, Dapper, - NpgsqlCopy + NpgsqlCopy, + ExternalBulkInsert } \ No newline at end of file diff --git a/test/PandaNuGet.Demo/PandaNuGet.Demo.csproj b/test/PandaNuGet.Demo/PandaNuGet.Demo.csproj index a0dbbc1..2bc0e0f 100644 --- a/test/PandaNuGet.Demo/PandaNuGet.Demo.csproj +++ b/test/PandaNuGet.Demo/PandaNuGet.Demo.csproj @@ -9,6 +9,7 @@ + diff --git a/test/PandaNuGet.Demo/Program.cs b/test/PandaNuGet.Demo/Program.cs index 417c4b3..706c81d 100644 --- a/test/PandaNuGet.Demo/Program.cs +++ b/test/PandaNuGet.Demo/Program.cs @@ -24,14 +24,17 @@ var results = new List { service.BulkInsertEfCore(minimumRows), - service.BulkInsertNpgsqlCopy(minimumRows), service.BulkInsertDapper(minimumRows), + service.BulkInsertNpgsqlCopy(minimumRows), + service.BulkInsertExternal(minimumRows), service.BulkInsertEfCore(minimumRows * 10), service.BulkInsertDapper(minimumRows * 10), service.BulkInsertNpgsqlCopy(minimumRows * 10), + service.BulkInsertExternal(minimumRows * 10), service.BulkInsertEfCore(minimumRows * 100), service.BulkInsertDapper(minimumRows * 100), - service.BulkInsertNpgsqlCopy(minimumRows * 100) + service.BulkInsertNpgsqlCopy(minimumRows * 100), + service.BulkInsertExternal(minimumRows * 100) }; return results; @@ -44,12 +47,15 @@ await service.BulkInsertEfCoreAsync(minimumRows), await service.BulkInsertDapperAsync(minimumRows), await service.BulkInsertNpgsqlCopyAsync(minimumRows), + await service.BulkInsertExternalAsync(minimumRows), await service.BulkInsertEfCoreAsync(minimumRows * 10), await service.BulkInsertDapperAsync(minimumRows * 10), await service.BulkInsertNpgsqlCopyAsync(minimumRows * 10), + await service.BulkInsertExternalAsync(minimumRows * 10), await service.BulkInsertEfCoreAsync(minimumRows * 100), await service.BulkInsertDapperAsync(minimumRows * 100), - await service.BulkInsertNpgsqlCopyAsync(minimumRows * 100) + await service.BulkInsertNpgsqlCopyAsync(minimumRows * 100), + await service.BulkInsertExternalAsync(minimumRows * 100) }; return results; diff --git a/test/PandaNuGet.Demo/Services/BulkInsertService.cs b/test/PandaNuGet.Demo/Services/BulkInsertService.cs index 7bdf3c3..220548b 100644 --- a/test/PandaNuGet.Demo/Services/BulkInsertService.cs +++ b/test/PandaNuGet.Demo/Services/BulkInsertService.cs @@ -1,6 +1,7 @@ using System.Diagnostics; using System.Text; using Dapper; +using EFCore.BulkExtensions; using EFCore.PostgresExtensions.Extensions.BulkInsertExtension; using Microsoft.EntityFrameworkCore; using PandaNuGet.Demo.Context; @@ -208,6 +209,42 @@ public async Task BulkInsertDapperAsync(int rowsCount, bo return new BulkBenchmarkResponse(BenchmarkMethod.Dapper, rowsCount, stopwatch.ElapsedMilliseconds.ToString()); } + public async Task BulkInsertExternalAsync(int rowsCount, bool ignoreReset = false) + { + await ResetDbAsync(ignoreReset); + var users = new List(); + + for (int i = 0; i < rowsCount; i++) + { + users.Add(new UserEntity()); + } + + var stopwatch = Stopwatch.StartNew(); + await dbContext.BulkInsertAsync(users); + stopwatch.Stop(); + + return new BulkBenchmarkResponse(BenchmarkMethod.ExternalBulkInsert, rowsCount, + stopwatch.ElapsedMilliseconds.ToString()); + } + + public BulkBenchmarkResponse BulkInsertExternal(int rowsCount, bool ignoreReset = false) + { + ResetDb(ignoreReset); + var users = new List(); + + for (int i = 0; i < rowsCount; i++) + { + users.Add(new UserEntity()); + } + + var stopwatch = Stopwatch.StartNew(); + dbContext.BulkInsert(users); + stopwatch.Stop(); + + return new BulkBenchmarkResponse(BenchmarkMethod.ExternalBulkInsert, rowsCount, + stopwatch.ElapsedMilliseconds.ToString()); + } + private async Task ResetDbAsync(bool ignore) { if (ignore) diff --git a/test/PandaNuGet.Demo/appsettings.json b/test/PandaNuGet.Demo/appsettings.json index f2af0c2..a19bffc 100644 --- a/test/PandaNuGet.Demo/appsettings.json +++ b/test/PandaNuGet.Demo/appsettings.json @@ -1,8 +1,8 @@ { "Logging": { "LogLevel": { - "Default": "Error", - "Microsoft.AspNetCore": "Error" + "Default": "Debug", + "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", From f93dafc7847829d49669959a8681703ca09623fd Mon Sep 17 00:00:00 2001 From: Haik Date: Sun, 26 May 2024 18:38:18 +0400 Subject: [PATCH 2/2] updated nugets --- .../EFCore.PostgresExtensions.csproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/EFCore.PostgresExtensions/EFCore.PostgresExtensions.csproj b/src/EFCore.PostgresExtensions/EFCore.PostgresExtensions.csproj index 19da96c..f19c6b5 100644 --- a/src/EFCore.PostgresExtensions/EFCore.PostgresExtensions.csproj +++ b/src/EFCore.PostgresExtensions/EFCore.PostgresExtensions.csproj @@ -8,13 +8,13 @@ Readme.md Pandatech MIT - 2.0.0 + 2.0.1 Pandatech.EFCore.PostgresExtensions Pandatech.EFCore.PostgresExtensions Pandatech, library, EntityFrameworkCore, PostgreSQL, For Update, Lock, LockingSyntax, Bulk insert, BinaryCopy The Pandatech.EFCore.PostgresExtensions library enriches Entity Framework Core applications with advanced PostgreSQL functionalities, starting with the ForUpdate locking syntax and BulkInsert function. Designed for seamless integration, this NuGet package aims to enhance the efficiency and capabilities of EF Core models when working with PostgreSQL, with the potential for further PostgreSQL-specific extensions. https://github.com/PandaTechAM/be-lib-efcore-postgres-extensions - Npgsql copy feature + NuGet updates