.NET 6.0
dotnet add package EntityFrameworkCore.Exceptions.SqlServer --version
NuGet\Install-Package EntityFrameworkCore.Exceptions.SqlServer -Version
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.SqlServer" Version="" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.Exceptions.SqlServer --version
#r "nuget: EntityFrameworkCore.Exceptions.SqlServer,"
#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.
// Install EntityFrameworkCore.Exceptions.SqlServer as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.Exceptions.SqlServer&version=

// Install EntityFrameworkCore.Exceptions.SqlServer as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.Exceptions.SqlServer&version=



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

License Target AppVeyor AppVeyor Coverage Status Ko-Fi

Maintainability Rating Vulnerabilities Bugs Code Smells Duplicated Lines (%) Coverage

Build Stats

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 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

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) such as UniqueConstraintException, CannotInsertNullException, MaxLengthExceededException, NumericOverflowException, ReferenceConstraintException you need.

How do I get started?

First, install the package corresponding to your database:

PM> Install-Package EntityFrameworkCore.Exceptions.SqlServer
PM> Install-Package EntityFrameworkCore.Exceptions.MySql
PM> Install-Package EntityFrameworkCore.Exceptions.MySql.Pomelo
PM> Install-Package EntityFrameworkCore.Exceptions.PostgreSQL
PM> Install-Package EntityFrameworkCore.Exceptions.Sqlite
PM> Install-Package EntityFrameworkCore.Exceptions.Oracle


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

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 OnConfiguring(DbContextOptionsBuilder optionsBuilder)

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 = "a",
        Price = 1

    demoContext.Products.Add(new Product
        Name = "a",
        Price = 1

    catch (UniqueConstraintException e)
        //Handle exception here
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (6)

Showing the top 5 NuGet packages that depend on EntityFrameworkCore.Exceptions.SqlServer:

Package Downloads

Provides extra authorization and multi-tenant features to a ASP.NET Core application.


Package Description


Package Description


Data repository package for the ALSIInvoices database



GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on EntityFrameworkCore.Exceptions.SqlServer:

Repository Stars
This library provides extra authorization and multi-tenant features to an ASP.NET Core application.
Version Downloads Last updated 135,740 6/1/2023 304,173 9/3/2022
6.0.3 93,430 3/16/2022
3.1.4 331,076 2/12/2021
3.1.1 62,346 1/22/2020
1.0.1 31,151 6/11/2019
1.0.0 1,245 1/23/2019
0.1.0-beta 668 12/5/2018

Update Microsoft.Data.SqlClient version

Treat 2628 error as MaxLengthExceededException