{"id":15002453,"url":"https://github.com/giorgi/entityframework.exceptions","last_synced_at":"2025-05-12T20:48:40.222Z","repository":{"id":37549507,"uuid":"159375164","full_name":"Giorgi/EntityFramework.Exceptions","owner":"Giorgi","description":"Strongly typed exceptions for Entity Framework Core. Supports SQLServer, PostgreSQL, SQLite, Oracle and  MySql.","archived":false,"fork":false,"pushed_at":"2025-04-26T22:12:05.000Z","size":331,"stargazers_count":1619,"open_issues_count":0,"forks_count":79,"subscribers_count":18,"default_branch":"main","last_synced_at":"2025-05-08T17:04:38.961Z","etag":null,"topics":["database-exceptions","dotnet-core","entity-framework","entity-framework-core","entityframework","mysql","netcore2","netcore3","odp-net","oracle","orm","postgresql","sql-server","sqlite","sqlite3"],"latest_commit_sha":null,"homepage":"https://giorgi.dev/entity-framework/introducing-entityframework-exceptions/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Giorgi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"License.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"Giorgi","buy_me_a_coffee":"giorgidev","ko_fi":"giorgi","open_collective":"entityframeworkexceptions"}},"created_at":"2018-11-27T17:39:35.000Z","updated_at":"2025-05-08T16:32:10.000Z","dependencies_parsed_at":"2024-01-01T04:04:18.557Z","dependency_job_id":"243050b9-ee51-426c-9ebb-9c7452697342","html_url":"https://github.com/Giorgi/EntityFramework.Exceptions","commit_stats":{"total_commits":285,"total_committers":15,"mean_commits":19.0,"dds":"0.14035087719298245","last_synced_commit":"ea1022b0753184376caa15a67f00df9c042f11f2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FEntityFramework.Exceptions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FEntityFramework.Exceptions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FEntityFramework.Exceptions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Giorgi%2FEntityFramework.Exceptions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Giorgi","download_url":"https://codeload.github.com/Giorgi/EntityFramework.Exceptions/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253819971,"owners_count":21969448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["database-exceptions","dotnet-core","entity-framework","entity-framework-core","entityframework","mysql","netcore2","netcore3","odp-net","oracle","orm","postgresql","sql-server","sqlite","sqlite3"],"created_at":"2024-09-24T18:50:25.696Z","updated_at":"2025-05-12T20:48:40.196Z","avatar_url":"https://github.com/Giorgi.png","language":"C#","readme":"![EntityFramework.Exceptions](https://raw.githubusercontent.com/Giorgi/EntityFramework.Exceptions/main/Icon.png \"EntityFramework.Exceptions\")\n\n# EntityFramework.Exceptions\nHandle database errors easily when working with Entity Framework Core. Supports SQLServer, PostgreSQL, SQLite, Oracle and MySql\n\n[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square\u0026logo=Apache)](License.md)\n[![Target](https://img.shields.io/static/v1?label=target\u0026message=net8.0\u0026color=512bd4\u0026logo=.net\u0026style=flat-square)](https://dotnet.microsoft.com/en-us/)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/Giorgi/EntityFramework.Exceptions/dotnet.yml)\n[![Coverage Status](https://img.shields.io/coveralls/github/Giorgi/EntityFramework.Exceptions?logo=coveralls\u0026style=flat-square)](https://coveralls.io/github/Giorgi/EntityFramework.Exceptions)\n[![Ko-Fi](https://img.shields.io/static/v1?style=flat-square\u0026message=Support%20the%20Project\u0026color=success\u0026style=plastic\u0026logo=ko-fi\u0026label=$$)](https://ko-fi.com/U6U81LHU8)\n\n[![](https://img.shields.io/nuget/dt/EntityFrameworkCore.Exceptions.SqlServer.svg?label=EntityFrameworkCore.Exceptions.SqlServer\u0026style=flat-square\u0026logo=Microsoft-Sql-Server)](https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.SqlServer/)\n[![](https://img.shields.io/nuget/dt/EntityFrameworkCore.Exceptions.PostgreSQL.svg?label=EntityFrameworkCore.Exceptions.PostgreSQL\u0026style=flat-square\u0026logo=PostgreSQL)](https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.PostgreSQL/)\n[![](https://img.shields.io/nuget/dt/EntityFrameworkCore.Exceptions.MySQL.svg?label=EntityFrameworkCore.Exceptions.MySQL\u0026style=flat-square\u0026logo=MySQL\u0026logoColor=white)](https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.MySQL/)\n[![](https://img.shields.io/nuget/dt/EntityFrameworkCore.Exceptions.MySQL.Pomelo.svg?label=EntityFrameworkCore.Exceptions.MySQL.Pomelo\u0026style=flat-square\u0026logo=MySQL\u0026logoColor=white)](https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.MySQL.Pomelo/)\n[![](https://img.shields.io/nuget/dt/EntityFrameworkCore.Exceptions.Sqlite.svg?label=EntityFrameworkCore.Exceptions.Sqlite\u0026style=flat-square\u0026logo=Sqlite)](https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.Sqlite/)\n[![](https://img.shields.io/nuget/dt/EntityFrameworkCore.Exceptions.Oracle.svg?label=EntityFrameworkCore.Exceptions.Oracle\u0026style=flat-square\u0026logo=Oracle)](https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.Oracle/)\n\n### Entity Framework Community Standup Live Show\n\n[![Entity Framework Community Standup - Typed Exceptions for Entity Framework Core](https://img.youtube.com/vi/aUl5QfswNU4/0.jpg)](https://www.youtube.com/watch?v=aUl5QfswNU4)\n\n### OSS Power-Ups: EntityFramework.Exceptions\n\n[![OSS Power-Ups: EntityFramework.Exceptions](https://img.youtube.com/vi/IwxqFd80Si8/0.jpg)](https://www.youtube.com/watch?v=IwxqFd80Si8)\n\n### Nick Chapsas - The Smart Way to Handle EF Core Exceptions\n\n[![Nick Chapsas - The Smart Way to Handle EF Core Exceptions](https://img.youtube.com/vi/QKwZlWvfh-o/0.jpg)](https://www.youtube.com/watch?v=QKwZlWvfh-o)\n\n## Sponsors\n\nA huge thanks to everyone (individuals or organisations) who have sponsored EntityFramework.Exceptions, but a massive thanks in particular to \n\n - [Entity Framework Extensions](https://entityframework-extensions.net/) and [Dapper Plus](https://dapper-plus.net/) are major sponsors and are proud to contribute to the development of EntityFramework.Exceptions\n - [JetBrains](https://www.jetbrains.com/) is sponsoring the EntityFramework.Exceptions project as part of their [OSS Power-Ups series](https://lp.jetbrains.com/oss-powerups/)\n\n[![Entity Framework Extensions - Sponsor](.github/sponsors/entity-framework-extensions-sponsr.png)](https://entityframework-extensions.net/bulk-insert)\n\n[![Dapper Plus - Sponsor](.github/sponsors/dapper-plus-sponsor.png)](https://dapper-plus.net/bulk-insert)\n\n\n## What does EntityFramework.Exceptions do?\n\nWhen using Entity Framework Core for data access all database exceptions are wrapped in `DbUpdateException`. If you need to find \nwhether the exception was caused by a unique constraint, value being too long or value missing for a required column you need to dig into \nthe concrete `DbException` subclass instance and check the error code to determine the exact cause.\n\nEntityFramework.Exceptions simplifies this by handling all the database specific details and throwing different exceptions. All you have\nto do is to configure `DbContext` by calling `UseExceptionProcessor` and handle the exception(s)  you need, such as `UniqueConstraintException`,\n`CannotInsertNullException`, `MaxLengthExceededException`, `NumericOverflowException`, or `ReferenceConstraintException`.\n\nIn 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. \n\n\u003e [!WARNING]\n\u003e `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](https://learn.microsoft.com/en-us/dotnet/api/microsoft.entityframeworkcore.migrations.migrationbuilder.sql?view=efcore-8.0) method.\n\n\u003e [!WARNING]\n\u003e `ConstraintName` and `ConstraintProperties` will not be populated when using SQLite. \n\nAll these exceptions inherit from `DbUpdateException` for backwards compatibility.\n\n### How do I get started?\nFirst, install the package corresponding to your database:\n\n```\ndotnet add package EntityFrameworkCore.Exceptions.SqlServer\n```\n\n```\ndotnet add package EntityFrameworkCore.Exceptions.MySql\n```\n\n```\ndotnet add package EntityFrameworkCore.Exceptions.MySql.Pomelo\n```\n\n```\ndotnet add package EntityFrameworkCore.Exceptions.PostgreSQL\n```\n\n```\ndotnet add package EntityFrameworkCore.Exceptions.Sqlite\n```\n\n```\ndotnet add package EntityFrameworkCore.Exceptions.Oracle\n```\n\nNext, in your DbContext `OnConfiguring` method call `UseExceptionProcessor` extension method:\n\n```csharp\nclass DemoContext : DbContext\n{\n    public DbSet\u003cProduct\u003e Products { get; set; }\n    public DbSet\u003cProductSale\u003e ProductSale { get; set; }\n\n    protected override void OnModelCreating(ModelBuilder builder)\n    {\n        builder.Entity\u003cProduct\u003e().HasIndex(u =\u003e u.Name).IsUnique();\n    }\n\n    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)\n    {\n        optionsBuilder.UseExceptionProcessor();\n    }\n}\n```    \n\nYou will now start getting different exception for different database error. For example, when a unique constraints fails you will get `UniqueConstraintException` exception:\n\n```csharp\nusing (var demoContext = new DemoContext())\n{\n    demoContext.Products.Add(new Product\n    {\n        Name = \"demo\",\n        Price = 10\n    });\n\n    demoContext.Products.Add(new Product\n    {\n        Name = \"demo\",\n        Price = 100\n    });\n\n    try\n    {\n        demoContext.SaveChanges();\n    }\n    catch (UniqueConstraintException e)\n    {\n        //Handle exception here\n        Console.WriteLine($\"Unique constraint {e.ConstraintName} violated. Duplicate value for {e.ConstraintProperties[0]}\");\n    }\n}\n```\n\u003e [!TIP]\n\u003e If you want to use another native SQLite binary instead of `e_sqlite3.dll` use the [EntityFrameworkCore.Exceptions.Sqlite.Core](https://www.nuget.org/packages/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.\n\n### Usage with DbContext pooling\n\nInstead of calling `UseExceptionProcessor` in the `OnConfiguring` method, add it where you add your `DbContextPool`:\n\n```csharp\n// Replace UseNpgsql with the sql flavor you're using\nbuilder.Services.AddDbContextPool\u003cDemoContext\u003e(options =\u003e options\n    .UseNpgsql(config.GetConnectionString(\"DemoConnection\"))\n    .UseExceptionProcessor());\n```\n","funding_links":["https://github.com/sponsors/Giorgi","https://buymeacoffee.com/giorgidev","https://ko-fi.com/giorgi","https://opencollective.com/entityframeworkexceptions","https://ko-fi.com/U6U81LHU8"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiorgi%2Fentityframework.exceptions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiorgi%2Fentityframework.exceptions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiorgi%2Fentityframework.exceptions/lists"}