VOOZH about

URL: https://www.nuget.org/packages/EntityFrameworkCore.Exceptions.MySQL.Pomelo/

⇱ NuGet Gallery | EntityFrameworkCore.Exceptions.MySQL.Pomelo 8.1.3


ο»Ώ

πŸ‘ Image
EntityFrameworkCore.Exceptions.MySQL.Pomelo 8.1.3

dotnet add package EntityFrameworkCore.Exceptions.MySQL.Pomelo --version 8.1.3
 
 
NuGet\Install-Package EntityFrameworkCore.Exceptions.MySQL.Pomelo -Version 8.1.3
 
 
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.MySQL.Pomelo" Version="8.1.3" />
 
 
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EntityFrameworkCore.Exceptions.MySQL.Pomelo" Version="8.1.3" />
 
Directory.Packages.props
<PackageReference Include="EntityFrameworkCore.Exceptions.MySQL.Pomelo" />
 
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.MySQL.Pomelo --version 8.1.3
 
 
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EntityFrameworkCore.Exceptions.MySQL.Pomelo, 8.1.3"
 
 
#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.MySQL.Pomelo@8.1.3
 
 
#: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.MySQL.Pomelo&version=8.1.3
 
Install as a Cake Addin
#tool nuget:?package=EntityFrameworkCore.Exceptions.MySQL.Pomelo&version=8.1.3
 
Install as a Cake Tool
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

πŸ‘ EntityFramework.Exceptions

EntityFramework.Exceptions

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

πŸ‘ 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

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.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 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]}");
 }
}

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());
Product Versions Compatible and additional computed target framework versions.
.NET net6.0 net6.0 is compatible.  net6.0-android net6.0-android was computed.  net6.0-ios net6.0-ios was computed.  net6.0-maccatalyst net6.0-maccatalyst was computed.  net6.0-macos net6.0-macos was computed.  net6.0-tvos net6.0-tvos was computed.  net6.0-windows net6.0-windows was computed.  net7.0 net7.0 was computed.  net7.0-android net7.0-android was computed.  net7.0-ios net7.0-ios was computed.  net7.0-maccatalyst net7.0-maccatalyst was computed.  net7.0-macos net7.0-macos was computed.  net7.0-tvos net7.0-tvos was computed.  net7.0-windows net7.0-windows was computed.  net8.0 net8.0 is compatible.  net8.0-android net8.0-android was computed.  net8.0-browser net8.0-browser was computed.  net8.0-ios net8.0-ios was computed.  net8.0-maccatalyst net8.0-maccatalyst was computed.  net8.0-macos net8.0-macos was computed.  net8.0-tvos net8.0-tvos was computed.  net8.0-windows net8.0-windows was computed.  net9.0 net9.0 was computed.  net9.0-android net9.0-android was computed.  net9.0-browser net9.0-browser was computed.  net9.0-ios net9.0-ios was computed.  net9.0-maccatalyst net9.0-maccatalyst was computed.  net9.0-macos net9.0-macos was computed.  net9.0-tvos net9.0-tvos was computed.  net9.0-windows net9.0-windows was computed.  net10.0 net10.0 was computed.  net10.0-android net10.0-android was computed.  net10.0-browser net10.0-browser was computed.  net10.0-ios net10.0-ios was computed.  net10.0-maccatalyst net10.0-maccatalyst was computed.  net10.0-macos net10.0-macos was computed.  net10.0-tvos net10.0-tvos was computed.  net10.0-windows net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

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

Package Downloads
devprime.stack.state

DevPrime State

FFCEI.Microservices

A free library for ASP.NET Core 6+ Microservices development, with Model, Model Repository, Entity Framework Core and common Web Api features like CORS, Json serialization fixes, Swagger generation, JWT Authentication for simple and objective microservices development

Identity.Module.API

A set of libraries to easily integrate and extend authentication in ASP.NET Core projects, using ASP.NET Core Identity.

Mii.Rinjani.Gateway.Commons.MySql

Package Description

Qiqigou.MyEFCore

EFCoreηš„εŒ…θ£…εΊ“

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.1.3 148,818 8/3/2024
8.1.2 42,733 3/22/2024
8.1.1 396 3/21/2024
8.1.0 532 3/16/2024
8.0.0 25,087 12/11/2023
6.0.3 109,883 3/16/2022
3.1.4 123,177 2/12/2021
3.1.2 22,093 4/23/2020

Add ConstraintName, ConstraintProperties and SchemaQualifiedTableName to UniqueConstraintException and ReferenceConstraintException