Table of Contents

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

ex DbUpdateException

The DbUpdateException to extract details from.

Returns

string

A constraint detail string, or null if 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

ex DbUpdateException

The DbUpdateException to classify.

Returns

bool

true if this is a duplicate key violation; otherwise false.

IsForeignKeyViolation(DbUpdateException)

Returns true if the exception represents a foreign key constraint violation.

public static bool IsForeignKeyViolation(DbUpdateException ex)

Parameters

ex DbUpdateException

The DbUpdateException to classify.

Returns

bool

true if this is a foreign key violation; otherwise false.