Giorgi / EntityFramework.Exceptions

Strongly typed exceptions for Entity Framework Core. Supports SQLServer, PostgreSQL, SQLite, Oracle and MySql.
https://giorgi.dev/entity-framework/introducing-entityframework-exceptions/
Other
1.51k stars 71 forks source link

Support for Microsoft.EntityFrameworkCore.Sqlite #11

Closed cdesch closed 4 years ago

cdesch commented 4 years ago

Is there a plan to provide support for Microsoft.EntityFrameworkCore.Sqlite? If there is, how can we contribute to it?

Giorgi commented 4 years ago

I didn't include SQLite because as I know some of the constrains are not enforced but if you find it useful you can send a PR.

cdesch commented 4 years ago

I created EntityFramework.Exceptions.Sqlite in this fork but as I saw that you commented, the error codes might not match up. I'll have figure out what the right error codes are.

Giorgi commented 4 years ago

I think the easiest option is to create a demo database, issue some inserts that cause errors and see what the error codes will be.

Giorgi commented 4 years ago

@cdesch Any progress?

Giorgi commented 4 years ago

Closing this due to inactivity. I will reopen it when someone sends a PR.

Aerion commented 4 years ago

It seems to me that the codes to catch are the following: https://sqlite.org/rescode.html#extrc The value to inspect in the SqliteException is not only SqliteErrorCode, but also SqliteExtendedErrorCode

For instance for an foreign key exception, I have a (DbUpdateException with an InnerException set to a) SqliteException with the following values :

From the sqlite link above, when we have a SqliteErrorCode with value 19

The SQLITE_CONSTRAINT error code means that an SQL constraint violation occurred while trying to process an SQL statement. Additional information about the failed constraint can be found by consulting the accompanying error message (returned via sqlite3_errmsg() or sqlite3_errmsg16()) or by looking at the extended error code.

And from the same link

SQLITE_CONSTRAINT_FOREIGNKEY (787)

I didn't do any more test, but I think this can help you @cdesch. I may have some time in a few days to try and send a PR if needed.

Giorgi commented 4 years ago

@Aerion Yes, a PR is welcome

Giorgi commented 4 years ago

The package is now available at EntityFrameworkCore.Exceptions.Sqlite