I’m upgrading Npgsql
from 7.0.11
to 8.0.2
/8.0.3
. There are a couple of types in PostgreSQL declared like this:
CREATE TYPE my_type AS ENUM (...)
In SQL, we try to insert or read these types like this:
SELECT foo::my_type FROM BAR
SELECT foo FROM BAR
INSERT INTO BAR(foo) VALUES(@Foo::my_type)
First, I started encountering errors like this:
Writing values of 'MyType[]' is not supported for parameters having no NpgsqlDbType or DataTypeName
Then I tried to mitigate it using the following code:
NpgsqlConnection.GlobalTypeMapper.MapEnum<MyType>("public.my_type", new CustomEnumTranslator());
And it seems that writing errors disappeared. However, the reading errors came up:
System.Data.DataException : Error parsing column 5 (foo=MyType[] - Object)
---- System.InvalidCastException : Unable to cast object of type 'MyType[]' to type 'System.String[]'.
Interestingly, the place where the exception occurs, works with the object value
method parameter. At runtime it has a value of MyType[2]
(array of 2 Enum values) and then it somehow tries to cast into string[]
.
Any ideas how to solve this?