-
Notifications
You must be signed in to change notification settings - Fork 875
Milestone
Description
Description
I have problems upgrading the packages from Npgsql and NetTopologySuite version 5.0.1.1 to 6.0.7
The code works fine on version 5.0.1.1
Steps to reproduce
CREATE TYPE testdto AS (
id int4,
loc geometry,
description varchar(100));
CREATE TABLE public.test (
id int4 NULL,
loc geometry(POINT) NULL,
description varchar(100) NULL
);
public class TestDto
{
[PgName("id")]
public int Id { get; set; }
[PgName("description")]
public string Description { get; set; }
[PgName("loc")]
public Point Location { get; set; }
}
CREATE OR REPLACE PROCEDURE public.sync_test(parameters testdto[])
LANGUAGE plpgsql
AS $procedure$
BEGIN
INSERT INTO test
select * FROM UNNEST(parameters::testdto[]);
END;
$procedure$
;
var par1 = new TestDto
{
Id = 1,
Location = new NetTopologySuite.Geometries.Point(-25.551136, -49.1929618) { SRID = 31983 },
Description = "test 1"
};
var par2 = new TestDto
{
Id = 2,
Location = new NetTopologySuite.Geometries.Point(-25.551136, -49.1929618) { SRID = 31983 },
Description = "test 2"
};
List<TestDto> l = new List<TestDto>();
l.Add(par1);
l.Add(par2);
NpgsqlConnection connection = new NpgsqlConnection(_connectionString);
try
{
connection.Open();
connection.TypeMapper.MapComposite<TestDto>("testdto");
connection.TypeMapper.UseNetTopologySuite();
NpgsqlCommand command = new NpgsqlCommand("", connection);
command.CommandText = "CALL sync_test(@parameters)";
var cmdParam1 = command.CreateParameter();
cmdParam1.ParameterName = "parameters";
cmdParam1.Value = l;
cmdParam1.DataTypeName = "testdto[]";
command.Parameters.Add(cmdParam1);
command.ExecuteNonQuery();
}
catch (Exception e)
{
_log.LogError(" Error:{error}" + e.ToString());
throw;
}
finally
{
connection.Close();
}
The issue
Exception message: System.Exception: 'While trying to write an array, one of its elements failed validation. You may be trying to mix types in a non-generic IList, or to write a jagged array.'
System.Exception
HResult=0x80131500
Message=While trying to write an array, one of its elements failed validation. You may be trying to mix types in a non-generic IList, or to write a jagged array.
Source=Npgsql
StackTrace:
em Npgsql.Internal.TypeHandlers.ArrayHandler`1.ValidateAndGetLengthNonGeneric(ICollection value, NpgsqlLengthCache& lengthCache)
em Npgsql.Internal.TypeHandlers.ArrayHandler`1.ValidateAndGetLength(Object value, NpgsqlLengthCache& lengthCache)
em Npgsql.Internal.TypeHandlers.ArrayHandler`1.ValidateObjectAndGetLength(Object value, NpgsqlLengthCache& lengthCache, NpgsqlParameter parameter)
em Npgsql.NpgsqlParameter.ValidateAndGetLength()
em Npgsql.NpgsqlParameterCollection.ValidateAndBind(ConnectorTypeMapper typeMapper)
em Npgsql.NpgsqlCommand.<ExecuteReader>d__116.MoveNext()
em System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
em Npgsql.NpgsqlCommand.<ExecuteReader>d__116.MoveNext()
em System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
em Npgsql.NpgsqlCommand.<ExecuteNonQuery>d__104.MoveNext()
em System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
em System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
em System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
em System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
em Npgsql.NpgsqlCommand.ExecuteNonQuery()
Esta exceção foi gerada originalmente nesta pilha de chamadas:
Npgsql.Internal.TypeHandlers.UnknownTypeHandler.ValidateObjectAndGetLength(object, ref Npgsql.Internal.TypeHandling.NpgsqlLengthCache, Npgsql.NpgsqlParameter)
Npgsql.Internal.TypeHandlers.ArrayHandler<TElement>.ValidateAndGetLengthNonGeneric(System.Collections.ICollection, ref Npgsql.Internal.TypeHandling.NpgsqlLengthCache)
Exceção interna 1:
InvalidCastException: Can't convert .NET type 'DapperAcessLibrary.DTO.TestDto' to PostgreSQL '.<unknown>' within an array
What needs to be changed to work the NetTopologySuite?
Further technical details
Npgsql version: 6.0.7
PostgreSQL version: 12
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels