PostgreSQL SMALLINT[] mapping fails in Dapper 2.1.86 but works in Dapper 2.1.79.
Environment
- .NET 10
- PostgreSQL
- Npgsql
- Dapper 2.1.86
Database
CREATE TABLE auto_numbers
(
item_name TEXT NOT NULL,
auto_column_name TEXT NOT NULL,
separator_positions SMALLINT[] NOT NULL DEFAULT ARRAY[]::SMALLINT[],
PRIMARY KEY (item_name, auto_column_name)
);
Example value:
INSERT INTO auto_numbers
(item_name, auto_column_name, separator_positions)
VALUES
('queue_visits', 'token_no', ARRAY[1]::SMALLINT[]);
Model
public sealed record AutoNumberRequest
{
public required string ItemName { get; init; }
public required string AutoColumnName { get; init; }
public required IReadOnlyList<short> SeparatorPositions { get; init; } = [];
}
Query
const string sql = """
SELECT
item_name "ItemName",
auto_column_name "AutoColumnName",
separator_positions "SeparatorPositions"
FROM auto_numbers
WHERE item_name = @ItemName
AND auto_column_name = @AutoColumnName
""";
var result = await connection.QuerySingleAsync<AutoNumberRequest>(
sql,
new
{
ItemName = "queue_visits",
AutoColumnName = "token_no"
});
Error with Dapper 2.1.86
System.Data.DataException:
Error parsing column 2 (SeparatorPositions=System.Int16[] - Int16[])
System.InvalidCastException:
Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
...
Npgsql returns the PostgreSQL SMALLINT[] value as System.Int16[].
Version comparison
With Dapper 2.1.79:
<PackageReference Include="Dapper" Version="[2.1.79]" />
the same query and model work correctly.
With Dapper 2.1.86:
<PackageReference Include="Dapper" Version="[2.1.86]" />
the query fails with the exception above.
I also tested changing the property from:
to:
and short[] also fails with Dapper 2.1.86.
No other application or database changes were made between the tests.
This appears to be a regression in Dapper 2.1.86 when reading PostgreSQL SMALLINT[] values through Npgsql.
Dapper 2.1.79 continues to work correctly with the same PostgreSQL database, Npgsql setup, query, and model.
PostgreSQL
SMALLINT[]mapping fails in Dapper 2.1.86 but works in Dapper 2.1.79.Environment
Database
Example value:
Model
Query
Error with Dapper 2.1.86
Npgsql returns the PostgreSQL
SMALLINT[]value asSystem.Int16[].Version comparison
With Dapper 2.1.79:
the same query and model work correctly.
With Dapper 2.1.86:
the query fails with the exception above.
I also tested changing the property from:
to:
and
short[]also fails with Dapper 2.1.86.No other application or database changes were made between the tests.
This appears to be a regression in Dapper 2.1.86 when reading PostgreSQL
SMALLINT[]values through Npgsql.Dapper 2.1.79 continues to work correctly with the same PostgreSQL database, Npgsql setup, query, and model.