Pandatech.EFCore.PostgresExtensions 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Pandatech.EFCore.PostgresExtensions --version 1.0.0
NuGet\Install-Package Pandatech.EFCore.PostgresExtensions -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pandatech.EFCore.PostgresExtensions" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Pandatech.EFCore.PostgresExtensions --version 1.0.0
#r "nuget: Pandatech.EFCore.PostgresExtensions, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Pandatech.EFCore.PostgresExtensions as a Cake Addin
#addin nuget:?package=Pandatech.EFCore.PostgresExtensions&version=1.0.0

// Install Pandatech.EFCore.PostgresExtensions as a Cake Tool
#tool nuget:?package=Pandatech.EFCore.PostgresExtensions&version=1.0.0

Pandatech.EFCore.PostgresExtensions

Pandatech.EFCore.PostgresExtensions is a NuGet package that enhances Entity Framework Core with support for PostgreSQL-specific syntax for update operations.

Introduction

You can install the Pandatech.EFCore.PostgresExtensions NuGet package via the NuGet Package Manager UI or the Package Manager Console using the following command: Install-Package Pandatech.EFCore.PostgresExtensions

Features

Adds support for PostgreSQL-specific update syntax. Simplifies handling of update operations when working with PostgreSQL databases.

Installation

  1. Install Pandatech.EFCore.PostgresExtensions Package Install-Package Pandatech.EFCore.PostgresExtensions

  2. Enable Query Locks

Inside the AddDbContext or AddDbContextPool method, after calling UseNpgsql(), call the UseQueryLocks() method on the DbContextOptionsBuilder to enable query locks.

services.AddDbContext<MyDbContext>(options =>
{
    options.UseNpgsql(Configuration.GetConnectionString("MyDatabaseConnection"))
           .UseQueryLocks();
});

Usage

Use the provided ForUpdate extension method on IQueryable within your application to apply PostgreSQL-specific update syntax.

using Pandatech.EFCore.PostgresExtensions;
using Microsoft.EntityFrameworkCore;

// Inside your service or repository method
using (var transaction = _dbContext.Database.BeginTransaction())
{
    try
    {
        // Use the ForUpdate extension method on IQueryable inside the transaction scope
        var entityToUpdate = _dbContext.Entities
            .Where(e => e.Id == id)
            .ForUpdate()
            .FirstOrDefault();

        // Perform updates on entityToUpdate

        await _dbContext.SaveChangesAsync();

        transaction.Commit();
    }
    catch (Exception ex)
    {
        transaction.Rollback();
        // Handle exception
    }
}

License

Pandatech.EFCore.PostgresExtensions is licensed under the MIT License.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pandatech.EFCore.PostgresExtensions:

Package Downloads
Pandatech.MassTransit.PostgresOutbox

Pandatech.MassTransit.PostgresOutbox extends MassTransit to offer advanced message handling capabilities for distributed systems. With first-class support for multiple DbContexts, this library integrates seamlessly with Entity Framework Core and PostgreSQL, providing reliable Outbox and Inbox patterns. It ensures consistent message delivery and processing in complex microservices architectures, leveraging PostgreSQL's ForUpdate feature to handle concurrency with ease.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.0 100 4/10/2024
1.0.0 151 3/29/2024

InitialCommit