EntityFrameworkCore.Exceptions.Oracle 11.0.0

dotnet add package EntityFrameworkCore.Exceptions.Oracle --version 11.0.0
                    
NuGet\Install-Package EntityFrameworkCore.Exceptions.Oracle -Version 11.0.0
                    
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="EntityFrameworkCore.Exceptions.Oracle" Version="11.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EntityFrameworkCore.Exceptions.Oracle" Version="11.0.0" />
                    
Directory.Packages.props
<PackageReference Include="EntityFrameworkCore.Exceptions.Oracle" />
                    
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 EntityFrameworkCore.Exceptions.Oracle --version 11.0.0
                    
#r "nuget: EntityFrameworkCore.Exceptions.Oracle, 11.0.0"
                    
#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 EntityFrameworkCore.Exceptions.Oracle@11.0.0
                    
#: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=EntityFrameworkCore.Exceptions.Oracle&version=11.0.0
                    
Install as a Cake Addin
#tool nuget:?package=EntityFrameworkCore.Exceptions.Oracle&version=11.0.0
                    
Install as a Cake Tool

EntityFramework.Exceptions

EntityFramework.Exceptions

Handle database errors easily when working with Entity Framework Core and ADO.NET. Supports SQLServer, PostgreSQL, SQLite, Oracle and MySql

License Target GitHub Actions Workflow Status Coverage Status Ko-Fi

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Entity Framework Community Standup Live Show

Entity Framework Community Standup - Typed Exceptions for Entity Framework Core

OSS Power-Ups: EntityFramework.Exceptions

OSS Power-Ups: EntityFramework.Exceptions

Nick Chapsas - The Smart Way to Handle EF Core Exceptions

Nick Chapsas - The Smart Way to Handle EF Core Exceptions

Sponsors

A huge thanks to everyone (individuals or organisations) who have sponsored EntityFramework.Exceptions, but a massive thanks in particular to

Entity Framework Extensions - Sponsor

Dapper Plus - Sponsor

What does EntityFramework.Exceptions do?

When using Entity Framework Core for data access all database exceptions are wrapped in DbUpdateException. If you need to find whether the exception was caused by a unique constraint, value being too long or value missing for a required column you need to dig into the concrete DbException subclass instance and check the error code to determine the exact cause.

EntityFramework.Exceptions simplifies this by handling all the database specific details and throwing different exceptions. All you have to do is to configure DbContext by calling UseExceptionProcessor and handle the exception(s) you need, such as UniqueConstraintException, CannotInsertNullException, MaxLengthExceededException, NumericOverflowException, or ReferenceConstraintException.

In case of UniqueConstraintException and ReferenceConstraintException you can get the name of the associated constraint with ConstraintName property. The ConstraintProperties will contain the properties that are part of the constraint.

ConstraintName and ConstraintProperties will be populated only if the index is defined in the Entity Framework Model. These properties will not be populated if the index exists in the database but isn't part of the model or if the index is added with MigrationBuilder.Sql method.

ConstraintName and ConstraintProperties will not be populated when using SQLite.

All these exceptions inherit from DbUpdateException for backwards compatibility.

How do I get started?

First, install the package corresponding to your database:

dotnet add package EntityFrameworkCore.Exceptions.SqlServer
dotnet add package EntityFrameworkCore.Exceptions.MySql
dotnet add package EntityFrameworkCore.Exceptions.PostgreSQL
dotnet add package EntityFrameworkCore.Exceptions.Sqlite
dotnet add package EntityFrameworkCore.Exceptions.Oracle

EntityFrameworkCore.Exceptions.MySql supports the official MySql.EntityFrameworkCore provider. If you use a MySqlConnector-based provider (Pomelo or its forks such as Microting.EntityFrameworkCore.MySql), see MySqlConnector-based providers.

Next, in your DbContext OnConfiguring method call UseExceptionProcessor extension method:

class DemoContext : DbContext
{
    public DbSet<Product> Products { get; set; }
    public DbSet<ProductSale> ProductSale { get; set; }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        builder.Entity<Product>().HasIndex(u => u.Name).IsUnique();
    }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        optionsBuilder.UseExceptionProcessor();
    }
}

You will now start getting different exception for different database error. For example, when a unique constraints fails you will get UniqueConstraintException exception:

using (var demoContext = new DemoContext())
{
    demoContext.Products.Add(new Product
    {
        Name = "demo",
        Price = 10
    });

    demoContext.Products.Add(new Product
    {
        Name = "demo",
        Price = 100
    });

    try
    {
        demoContext.SaveChanges();
    }
    catch (UniqueConstraintException e)
    {
        //Handle exception here
        Console.WriteLine($"Unique constraint {e.ConstraintName} violated. Duplicate value for {e.ConstraintProperties[0]}");
    }
}

If you want to use another native SQLite binary instead of e_sqlite3.dll use the EntityFrameworkCore.Exceptions.Sqlite.Core package. This package depends on Microsoft.Data.Sqlite.Core package, which doesn't include SQLite native binary so you can use any native binary you want.

Usage with DbContext pooling

Instead of calling UseExceptionProcessor in the OnConfiguring method, add it where you add your DbContextPool:

// Replace UseNpgsql with the sql flavor you're using
builder.Services.AddDbContextPool<DemoContext>(options => options
    .UseNpgsql(config.GetConnectionString("DemoConnection"))
    .UseExceptionProcessor());

Using a provider without a dedicated package

If your database provider has no EntityFrameworkCore.Exceptions.* package (for example, Devart dotConnect providers), implement IDbExceptionClassifier yourself and pass it to UseExceptionProcessor. This overload lives in the base EntityFrameworkCore.Exceptions.Common package, so you can reference that package directly:

For example, with Devart dotConnect for PostgreSQL, classify errors by the SQLSTATE code exposed by PgSqlException.ErrorCode:

using System.Data.Common;
using DbExceptionClassifier.Common;
using Devart.Data.PostgreSql;
using EntityFramework.Exceptions.Common;

public class DevartPostgreSqlExceptionClassifier : IDbExceptionClassifier
{
    public bool IsReferenceConstraintError(DbException exception) => exception is PgSqlException { ErrorCode: "23503" or "23001" }; // foreign_key_violation, restrict_violation
    public bool IsCannotInsertNullError(DbException exception) => exception is PgSqlException { ErrorCode: "23502" };             // not_null_violation
    public bool IsNumericOverflowError(DbException exception) => exception is PgSqlException { ErrorCode: "22003" };              // numeric_value_out_of_range
    public bool IsUniqueConstraintError(DbException exception) => exception is PgSqlException { ErrorCode: "23505" };             // unique_violation
    public bool IsMaxLengthExceededError(DbException exception) => exception is PgSqlException { ErrorCode: "22001" };            // string_data_right_truncation
    public bool IsDeadlockError(DbException exception) => exception is PgSqlException { ErrorCode: "40P01" };                     // deadlock_detected
}

optionsBuilder
    .UsePostgreSql(connectionString)
    .UseExceptionProcessor(new DevartPostgreSqlExceptionClassifier());

The same approach works for any other ADO.NET provider: check the provider's exception type and its error codes.

ConstraintName and ConstraintProperties are populated the same way as for built-in providers: by matching constraint names from the EF Core model against the database error message.

MySqlConnector-based providers

There is no dedicated package for EF Core providers built on MySqlConnector, such as Pomelo.EntityFrameworkCore.MySql and its forks such as Microting.EntityFrameworkCore.MySql. You don't need to write a classifier for them: the DbExceptionClassifier.MySqlConnector package already has one for MySqlConnector.

dotnet add package EntityFrameworkCore.Exceptions.Common
dotnet add package DbExceptionClassifier.MySqlConnector
using DbExceptionClassifier.MySqlConnector;
using EntityFramework.Exceptions.Common;

optionsBuilder
    .UseMySql(connectionString, serverVersion)
    .UseExceptionProcessor(new MySqlConnectorExceptionClassifier());

DbExceptionClassifier

If you don't use Entity Framework Core, you can use the DbExceptionClassifier packages to classify ADO.NET database exceptions directly. They provide a unified IDbExceptionClassifier interface without any EF Core dependency.

dotnet add package DbExceptionClassifier.PostgreSQL
var classifier = new PostgreSQLExceptionClassifier();

try
{
    await command.ExecuteNonQueryAsync();
}
catch (DbException ex) when (classifier.IsUniqueConstraintError(ex))
{
    // Handle unique constraint violation
}

See the DbExceptionClassifier README for full documentation.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
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
11.0.0 61 11/20/2026
10.0.2 312 11/16/2026
10.0.1 9,490 5/24/2026
10.0.0 3,217 3/19/2026
8.1.3 42,564 8/3/2024
8.1.2 4,579 3/22/2024
8.1.1 386 3/21/2024
8.1.0 1,461 3/16/2024
8.0.0 2,554 12/11/2023
6.0.3 9,999 3/16/2022
3.1.4 3,819 2/12/2021
3.1.1 850 11/5/2020

- Update to .NET 11 and Entity Framework Core 11
- Add UseExceptionProcessor overload that accepts a custom IDbExceptionClassifier
- Populate ConstraintName and ConstraintProperties for alternate key violations
- Fix constraint details when one constraint name contains another (for example IX_Users and IX_Users_Name): the longest matching name is now used
- EntityFrameworkCore.Exceptions.MySQL.Pomelo is discontinued. With Pomelo or other MySqlConnector-based providers, use UseExceptionProcessor(new MySqlConnectorExceptionClassifier()) from the DbExceptionClassifier.MySqlConnector package