Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql
1.0.0-preview.4
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
<PackageReference Include="Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql" Version="1.0.0-preview.4" />
<PackageVersion Include="Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql" Version="1.0.0-preview.4" />
<PackageReference Include="Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql" />
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"
#:package Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql@1.0.0-preview.4
#addin nuget:?package=Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql&version=1.0.0-preview.4&prerelease
#tool nuget:?package=Tolitech.Infrastructure.Persistence.ConstraintValidator.PostgreSql&version=1.0.0-preview.4&prerelease
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 | Versions 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. |
-
net9.0
- Npgsql (>= 9.0.3)
- Tolitech.Infrastructure.Persistence.ConstraintValidator (>= 1.0.0-preview.5)
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 |