Skip to content

Commit 7543192

Browse files
committed
Update to .NET 10 and EF Core 10
1 parent 33ce832 commit 7543192

File tree

19 files changed

+194
-41
lines changed

19 files changed

+194
-41
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
- name: Setup .NET
2121
uses: actions/setup-dotnet@v4
2222
with:
23-
dotnet-version: 9.0.200
23+
dotnet-version: 10.0.x
2424
- name: Restore dependencies
2525
run: dotnet restore
2626
- name: Build

.github/workflows/sonarcloud.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
- name: Setup .NET
6363
uses: actions/setup-dotnet@v4
6464
with:
65-
dotnet-version: 9.0.200
65+
dotnet-version: 10.0.x
6666

6767
- name: Build and analyze
6868
env:
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<PackageTags>Exception Database DbException ADO.NET</PackageTags>
7+
<Description>Classify database exceptions by error type. This is a base package for database specific packages. Install one of the specific packages instead of this</Description>
78
</PropertyGroup>
89

910
</Project>

DbExceptionClassifier/Directory.Build.props

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,17 @@
55
<AssemblyName>DbExceptionClassifier.$(MSBuildProjectName)</AssemblyName>
66
<RootNamespace>$(AssemblyName)</RootNamespace>
77
<PackageId>DbExceptionClassifier.$(MSBuildProjectName)</PackageId>
8+
<Version>1.0.0</Version>
9+
<FileVersion>1.0.0</FileVersion>
10+
<AssemblyVersion>1.0.0</AssemblyVersion>
11+
<PackageReleaseNotes>Initial release</PackageReleaseNotes>
812
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<None Remove="..\..\README.md" />
16+
<None Include="..\README.md">
17+
<Pack>True</Pack>
18+
<PackagePath></PackagePath>
19+
</None>
20+
</ItemGroup>
921
</Project>

DbExceptionClassifier/MySQL.Pomelo/MySQL.Pomelo.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<PackageTags>Exception Database DbException ADO.NET MySQL MySqlConnector Pomelo</PackageTags>
7+
<Description>Classify MySQL database exceptions by error type such as unique constraint violation, foreign key violation, and more. Use this package if you use MySqlConnector</Description>
78
</PropertyGroup>
8-
9+
910
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
1011
<DefineConstants>TRACE;POMELO</DefineConstants>
1112
</PropertyGroup>
@@ -19,7 +20,7 @@
1920
</ItemGroup>
2021

2122
<ItemGroup>
22-
<PackageReference Include="MySqlConnector" Version="2.4.0" />
23+
<PackageReference Include="MySqlConnector" Version="2.5.0" />
2324
</ItemGroup>
2425

2526
</Project>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<PackageTags>Exception Database DbException ADO.NET MySQL</PackageTags>
7+
<Description>Classify MySQL database exceptions by error type such as unique constraint violation, foreign key violation, and more</Description>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="MySql.Data" Version="8.3.0" />
11+
<PackageReference Include="MySql.Data" Version="9.6.0" />
1112
</ItemGroup>
1213
</Project>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<PackageTags>Exception Database DbException ADO.NET Oracle ODP.NET</PackageTags>
7+
<Description>Classify Oracle database exceptions by error type such as unique constraint violation, foreign key violation, and more</Description>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21.120" />
11+
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="23.26.100" />
1112
</ItemGroup>
1213
</Project>
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<PackageTags>Exception Database DbException ADO.NET PostgreSQL Npgsql</PackageTags>
7+
<Description>Classify PostgreSQL database exceptions by error type such as unique constraint violation, foreign key violation, and more</Description>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="Npgsql" Version="8.0.6" />
11+
<PackageReference Include="Npgsql" Version="10.0.2" />
1112
</ItemGroup>
1213

1314
</Project>

DbExceptionClassifier/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
![EntityFramework.Exceptions](https://raw.githubusercontent.com/Giorgi/EntityFramework.Exceptions/main/Icon.png "EntityFramework.Exceptions")
2+
3+
# DbExceptionClassifier
4+
5+
Classify ADO.NET database exceptions by error type. Works with any ADO.NET provider without requiring Entity Framework Core.
6+
7+
Supports **PostgreSQL**, **SQL Server**, **SQLite**, **Oracle**, **MySQL** (MySql.Data and MySqlConnector).
8+
9+
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square&logo=Apache)](License.md)
10+
[![Target](https://img.shields.io/static/v1?label=target&message=net10.0&color=512bd4&logo=.net&style=flat-square)](https://dotnet.microsoft.com/en-us/)
11+
12+
## What does DbExceptionClassifier do?
13+
14+
When working with ADO.NET, database exceptions are provider-specific. To determine whether an error was caused by a unique constraint violation, a foreign key violation, or a null constraint, you need to inspect the provider-specific exception type and error codes.
15+
16+
DbExceptionClassifier provides a unified `IDbExceptionClassifier` interface that classifies `DbException` instances into common error types:
17+
18+
- **Unique constraint violation**
19+
- **Reference (foreign key) constraint violation**
20+
- **Cannot insert null**
21+
- **Max length exceeded**
22+
- **Numeric overflow**
23+
- **Deadlock**
24+
25+
## Getting started
26+
27+
Install the package for your database:
28+
29+
```
30+
dotnet add package DbExceptionClassifier.PostgreSQL
31+
```
32+
33+
```
34+
dotnet add package DbExceptionClassifier.SqlServer
35+
```
36+
37+
```
38+
dotnet add package DbExceptionClassifier.Sqlite.Core
39+
```
40+
41+
```
42+
dotnet add package DbExceptionClassifier.Oracle
43+
```
44+
45+
```
46+
dotnet add package DbExceptionClassifier.MySQL
47+
```
48+
49+
```
50+
dotnet add package DbExceptionClassifier.MySQL.Pomelo
51+
```
52+
53+
## Usage
54+
55+
Create an instance of the classifier for your database and use it to classify exceptions:
56+
57+
```csharp
58+
var classifier = new PostgreSQLExceptionClassifier();
59+
60+
try
61+
{
62+
// Execute your ADO.NET command
63+
await command.ExecuteNonQueryAsync();
64+
}
65+
catch (DbException ex) when (classifier.IsUniqueConstraintError(ex))
66+
{
67+
// Handle unique constraint violation
68+
}
69+
catch (DbException ex) when (classifier.IsReferenceConstraintError(ex))
70+
{
71+
// Handle foreign key violation
72+
}
73+
```
74+
75+
## IDbExceptionClassifier interface
76+
77+
```csharp
78+
public interface IDbExceptionClassifier
79+
{
80+
bool IsUniqueConstraintError(DbException exception);
81+
bool IsReferenceConstraintError(DbException exception);
82+
bool IsCannotInsertNullError(DbException exception);
83+
bool IsMaxLengthExceededError(DbException exception);
84+
bool IsNumericOverflowError(DbException exception);
85+
bool IsDeadlockError(DbException exception);
86+
}
87+
```
88+
89+
## CompositeExceptionClassifier
90+
91+
If your application connects to multiple database types, use `CompositeExceptionClassifier` to combine multiple classifiers into one. It delegates to each classifier and returns `true` if any of them matches:
92+
93+
```csharp
94+
var classifier = new CompositeExceptionClassifier(
95+
new PostgreSQLExceptionClassifier(),
96+
new SqlServerExceptionClassifier()
97+
);
98+
99+
try
100+
{
101+
await command.ExecuteNonQueryAsync();
102+
}
103+
catch (DbException ex) when (classifier.IsUniqueConstraintError(ex))
104+
{
105+
// Works regardless of which database threw the exception
106+
}
107+
```
108+
109+
## Entity Framework Core
110+
111+
If you are using Entity Framework Core, use the [EntityFrameworkCore.Exceptions](https://github.com/Giorgi/EntityFramework.Exceptions) packages instead. They build on top of DbExceptionClassifier and provide typed exceptions that inherit from `DbUpdateException`.
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
6+
<PackageTags>Exception Database DbException ADO.NET SqlServer</PackageTags>
7+
<Description>Classify SQL Server database exceptions by error type such as unique constraint violation, foreign key violation, and more</Description>
78
</PropertyGroup>
89

910
<ItemGroup>
10-
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
11+
<PackageReference Include="Microsoft.Data.SqlClient" Version="7.0.0" />
1112
</ItemGroup>
1213

1314
</Project>

0 commit comments

Comments
 (0)