Hi,
First, thanks for providing such a great project!
I've encountered a situation where Npgsql seems to lack a default type mapping for short arrays to Postgre smallint[] fields within composite types. Below are the details:
Steps to reproduce
using Npgsql;
// 1. Assuming a PostgreSQL setup with the following type and table:
CREATE TYPE public.inventory_item AS
(
name text,
supplier_id integer,
price numeric,
shortlist smallint[]
);
CREATE TABLE some_table (
id serial PRIMARY KEY,
my_composite inventory_item
);
// 2. C# code that demonstrates the issue:
public class InventoryItem
{
public string Name { get; set; } = "";
public int SupplierId { get; set; }
public decimal Price { get; set; }
public short[] ShortList { get; set; }
}
// (Code for connection setup using NpgsqlDataSourceBuilder)
await using var conn = dataSource.CreateConnection();
await conn.OpenAsync();
await using var cmdWriting = new NpgsqlCommand("INSERT INTO public.some_table (my_composite) VALUES (@composite)", conn);
var inventoryItem = new InventoryItem
{
Name = "InventoryItemName",
SupplierId = 4323,
Price = 300.0m,
ShortList = new short[] { 1, 2, 3 }
};
cmdWriting.Parameters.AddWithValue("@composite", inventoryItem);
await cmdWriting.ExecuteNonQueryAsync();
The issue
The code above produces the following errors:
-
System.InvalidCastException: 'Writing values of 'npg_composite_mapping_object_issue.InventoryItem' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..'
-
InvalidOperationException: Cannot find property or field for composite field 'shortlist'.
The issue is the lack of a default type handler within Npgsql to map a C# short[] property to a PostgreSQL smallint[] field in a composite type.
Further technical details
- Npgsql version: 8.0.2
- Operating system: Windows and macOS
Hi,
First, thanks for providing such a great project!
I've encountered a situation where Npgsql seems to lack a default type mapping for short arrays to Postgre smallint[] fields within composite types. Below are the details:
Steps to reproduce
The issue
The code above produces the following errors:
System.InvalidCastException: 'Writing values of 'npg_composite_mapping_object_issue.InventoryItem' is not supported for parameters having no NpgsqlDbType or DataTypeName. Try setting one of these values to the expected database type..'InvalidOperationException: Cannot find property or field for composite field 'shortlist'.The issue is the lack of a default type handler within Npgsql to map a C#
short[]property to a PostgreSQLsmallint[]field in a composite type.Further technical details