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.44k stars 68 forks source link

MaxLengthExceededException not being thrown when using SQL Server 2019 #52

Closed johnavery closed 2 years ago

johnavery commented 2 years ago

Hello, I just integrated your library into my code, and to test, I attempted to produce a MaxLengthExceededException by setting a 32 character field to 33 characters. To my surprise, instead of catching a MaxLengthExceededException, I instead caught a plain-old DbUpdateException.

I viewed the code in SqlServerExceptionProcessorInterceptor, and I see that you are matching that exception up with error 8152, but for SQL Server 2019, that error code has been replaced by 2628 (see: String or Binary data would be truncated: replacing the infamous error 8152).

Can you please update the package such that it would treat either code as a MaxLengthExceededException? For now I can workaround by inspecting the error number manually. Thanks!

Giorgi commented 2 years ago

@johnavery Thanks for bringing this to my attention. Do you want to create a PR as well for this issue? Should be straightforward to add this.

johnavery commented 2 years ago

All set.

Giorgi commented 2 years ago

Thanks, I'll publish a new version tomorrow.

Giorgi commented 2 years ago

@johnavery New version published on NuGet