Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql 1.0.0-preview.4

This is a prerelease version of Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql.
dotnet add package Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql --version 1.0.0-preview.4
                    
NuGet\Install-Package Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql -Version 1.0.0-preview.4
                    
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="Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql" Version="1.0.0-preview.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql" Version="1.0.0-preview.4" />
                    
Directory.Packages.props
<PackageReference Include="Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql --version 1.0.0-preview.4
                    
#r "nuget: Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql, 1.0.0-preview.4"
                    
#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.
#:package Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql@1.0.0-preview.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql&version=1.0.0-preview.4&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql&version=1.0.0-preview.4&prerelease
                    
Install as a Cake Tool

Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql

A static library for managing and validating database constraint exceptions specifically for PostgreSQL.

Overview

This package provides a PostgreSQL-specific implementation of the constraint validator interface, allowing you to handle integrity exceptions (primary key, foreign key, not null, check) thrown by PostgreSQL and convert them into custom exceptions for your application.

Installation

dotnet add package Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql

Usage

1. Register the PostgreSQL validator

using Tolitech.Infrastructure.Persistence.ConstraintValidator;
using Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql;

ConstraintValidatorManager.AddValidator(new PostgreSqlConstraintValidator());

2. Handle PostgreSQL exceptions

try
{
    // Database operation
}
catch (Exception ex)
{
    Exception handled = ConstraintValidatorManager.Handle(ex);
    if (handled is DatabaseConstraintViolationException)
    {
        // Custom logic for constraint violations
    }
}

Supported PostgreSQL Constraint Violations

  • Primary key violation: SqlState = "23505"
  • Foreign key violation: SqlState = "23503"
  • Check constraint violation: SqlState = "23514"
  • Not null violation: SqlState = "23502"

Advanced

You can remove or clear validators:

ConstraintValidatorManager.RemoveValidator(yourValidator);
ConstraintValidatorManager.ClearValidators();

Example: Entity Framework Core

try
{
    await dbContext.SaveChangesAsync();
}
catch (Exception ex)
{
    var handled = ConstraintValidatorManager.Handle(ex);
    if (handled is PrimaryKeyViolationException)
        // Notify user about duplicate
}

Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql makes handling PostgreSQL constraint exceptions simple and robust.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview.4 37 7/18/2025
1.0.0-preview.3 110 7/14/2025
1.0.0-preview.2 123 7/3/2025
1.0.0-preview.1 72 12/12/2024