Pandatech.EFCore.PostgresExtensions
2.0.0
See the version list below for details.
dotnet add package Pandatech.EFCore.PostgresExtensions --version 2.0.0
NuGet\Install-Package Pandatech.EFCore.PostgresExtensions -Version 2.0.0
<PackageReference Include="Pandatech.EFCore.PostgresExtensions" Version="2.0.0" />
<PackageVersion Include="Pandatech.EFCore.PostgresExtensions" Version="2.0.0" />
<PackageReference Include="Pandatech.EFCore.PostgresExtensions" />
paket add Pandatech.EFCore.PostgresExtensions --version 2.0.0
#r "nuget: Pandatech.EFCore.PostgresExtensions, 2.0.0"
#:package Pandatech.EFCore.PostgresExtensions@2.0.0
#addin nuget:?package=Pandatech.EFCore.PostgresExtensions&version=2.0.0
#tool nuget:?package=Pandatech.EFCore.PostgresExtensions&version=2.0.0
1. Pandatech.EFCore.PostgresExtensions
Pandatech.EFCore.PostgresExtensions is an advanced NuGet package designed to enhance PostgreSQL functionalities within Entity Framework Core, leveraging specific features not covered by the official Npgsql.EntityFrameworkCore.PostgreSQL package. This package introduces optimized row-level locking mechanisms and an efficient, typed version of the PostgreSQL COPY operation, adhering to EF Core syntax for seamless integration into your projects.
1.1. Features
- Row-Level Locking: Implements the PostgreSQL
FOR UPDATEfeature, providing three lock behaviors -Wait,Skip, andNoWait, to facilitate advanced transaction control and concurrency management. - Npgsql COPY Integration: Offers a high-performance, typed interface for the PostgreSQL COPY command, allowing for bulk data operations within the EF Core framework. This feature significantly enhances data insertion speeds and efficiency.
1.2. Installation
To install Pandatech.EFCore.PostgresExtensions, use the following NuGet command:
Install-Package Pandatech.EFCore.PostgresExtensions
1.3. Usage
1.3.1. Row-Level Locking
Configure your DbContext to use Npgsql and enable query locks:
services.AddDbContext<MyDbContext>(options =>
{
options.UseNpgsql(Configuration.GetConnectionString("MyDatabaseConnection"))
.UseQueryLocks();
});
Within a transaction scope, apply the desired lock behavior using the ForUpdate extension method:
using var transaction = _dbContext.Database.BeginTransaction();
try
{
var entityToUpdate = _dbContext.Entities
.Where(e => e.Id == id)
.ForUpdate(LockBehavior.NoWait) // Or use LockBehavior.Default (Wait)/ LockBehavior.SkipLocked
.FirstOrDefault();
// Perform updates on entityToUpdate
await _dbContext.SaveChangesAsync();
transaction.Commit();
}
catch (Exception ex)
{
transaction.Rollback();
// Handle exception
}
1.3.2. Npgsql COPY Integration
For bulk data operations, use the BulkInsert or BulkInsertAsync extension methods:
public async Task BulkInsertExampleAsync()
{
var users = new List<UserEntity>();
for (int i = 0; i < 10000; i++)
{
users.Add(new UserEntity { /* Initialization */ });
}
await dbContext.Users.BulkInsertAsync(users); // Or use BulkInsert for synchronous operation
// It also saves changes to the database
}
1.3.2.1. Benchmarks
The integration of the Npgsql COPY command showcases significant performance improvements compared to traditional EF Core and Dapper methods:
1.3.2.1.1. General Benchmark Results
| Caption | Big O Notation | 1M Rows | Batch Size |
|---|---|---|---|
| BulkInsert | O(log n) | 350.000 r/s | No batch |
| Dapper | O(n) | 20.000 r/s | 1500 |
| EFCore | O(n) | 10.600 r/s | 1500 |
1.3.2.1.2. Detailed Benchmark Results
| Operation | BulkInsert | Dapper | EF Core |
|---|---|---|---|
| Insert 10K | 76ms | 535ms | 884ms |
| Insert 100K | 405ms | 5.47s | 8.58s |
| Insert 1M | 2.87s | 55.85s | 94.57s |
1.3.2.1.3. Efficiency Comparison
| RowsCount | BulkInsert Efficiency | Dapper Efficiency |
|---|---|---|
| 10K | 11.63x faster than EF Core | 1.65x faster than EF Core |
| 100K | 21.17x faster than EF Core | 1.57x faster than EF Core |
| 1M | 32.95x faster than EF Core | 1.69x faster than EF Core |
1.3.2.1.4. Additional Notes
The
BulkInsertfeature currently does not support entity properties intended forJSONstorage.The performance metrics provided above are based on benchmarks conducted under controlled conditions. Real-world performance may vary based on specific use cases and configurations.
1.4. License
Pandatech.EFCore.PostgresExtensions is licensed under the MIT License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Pandatech.EFCore.PostgresExtensions:
| Package | Downloads |
|---|---|
|
Pandatech.SharedKernel.Postgres
PostgreSQL integration helpers for ASP.NET Core 10: DbContext registration with or without pooling and audit trail, migrations, health checks, snake_case naming, query locks, exception mapping, and bulk extensions. |
|
|
Pandatech.MassTransit.PostgresOutbox
Outbox and Inbox pattern implementation for MassTransit with PostgreSQL and EF Core. Supports multiple DbContexts for modular monolith and microservice architectures. Uses PostgreSQL FOR UPDATE SKIP LOCKED for concurrency control. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 7.0.0 | 530 | 2/28/2026 |
| 6.2.0 | 764 | 2/21/2026 |
| 6.1.0 | 2,875 | 1/26/2026 |
| 6.0.0 | 636 | 12/28/2025 |
| 5.1.3 | 18,381 | 8/7/2025 |
| 5.1.2 | 364 | 6/1/2025 |
| 5.1.1 | 250 | 5/6/2025 |
| 5.1.0 | 355 | 3/31/2025 |
| 5.0.0 | 239 | 3/31/2025 |
| 4.0.2 | 369 | 3/12/2025 |
| 4.0.1 | 677 | 2/17/2025 |
| 4.0.0 | 2,061 | 11/21/2024 |
| 3.0.0 | 21,282 | 7/17/2024 |
| 2.0.1 | 350 | 5/26/2024 |
| 2.0.0 | 213 | 4/10/2024 |
| 1.0.0 | 390 | 3/29/2024 |
Npgsql copy feature