NpgsqlException 上的代码属性

Nei*_*enn 3 npgsql

我试图在我的代码中从 NPGSQL 的 v2.0.11 移动到 v3.1.7,但是我正在访问 NpgsqlException 的代码属性。在 3.1.7 中这已经消失了;我现在如何从 postgres 访问底层代码错误?

Sha*_*sky 5

在 Npgsql 3.1 中,PostgreSQL 错误被抛出为 PostgresException,而不是 NpgsqlException(这是为其他错误保留的,例如网络问题)。如果您捕获 PostgresException,您将找到SqlState已被替换的属性Code(它仍然存在但已过时)。