Class DbExceptionClassifier
- Namespace
- Trellis.EntityFrameworkCore
- Assembly
- Trellis.EntityFrameworkCore.dll
Classifies database exceptions across providers (SQL Server, PostgreSQL, SQLite). Used internally by both SaveChangesResultAsync(DbContext, CancellationToken) and SaveChangesResultAsync(DbContext, bool, CancellationToken) overloads. Also available for direct use in repositories that need custom error messages per exception type.
public static class DbExceptionClassifier
- Inheritance
-
DbExceptionClassifier
- Inherited Members
Methods
ExtractConstraintDetail(DbUpdateException)
Attempts to extract a human-readable constraint detail from the exception.
Returns the constraint name or violated column if available, otherwise null.
public static string? ExtractConstraintDetail(DbUpdateException ex)
Parameters
exDbUpdateExceptionThe DbUpdateException to extract details from.
Returns
- string
A constraint detail string, or
nullif no detail can be extracted.
IsDuplicateKey(DbUpdateException)
Returns true if the exception represents a unique constraint violation (duplicate key).
public static bool IsDuplicateKey(DbUpdateException ex)
Parameters
exDbUpdateExceptionThe DbUpdateException to classify.
Returns
- bool
trueif this is a duplicate key violation; otherwisefalse.
IsForeignKeyViolation(DbUpdateException)
Returns true if the exception represents a foreign key constraint violation.
public static bool IsForeignKeyViolation(DbUpdateException ex)
Parameters
exDbUpdateExceptionThe DbUpdateException to classify.
Returns
- bool
trueif this is a foreign key violation; otherwisefalse.