Combine multiple classifiers with CompositeExceptionClassifier
mainIf your application interacts with multiple different database types, use CompositeExceptionClassifier to wrap multiple specific classifiers. The composite classifier will iterate through its registered classifiers and return true if any of them identify the exception type.
var classifier = new CompositeExceptionClassifier(
new PostgreSQLExceptionClassifier(),
new SqlServerExceptionClassifier()
);
try
{
await command.ExecuteNonQueryAsync();
}
catch (DbException ex) when (classifier.IsUniqueConstraintError(ex))
{
// Works regardless of which database threw the exception
}