I've read several questions and topics related to the issue but none of them actually helped me to solve my problem and none of them actually were related to C#. And here is the actual problem:
I have a Postgre composite type:
CREATE TYPE law_relation_update_model AS (
from_celex character varying,
from_article character varying,
to_celex character varying,
to_article character varying,
link_ids integer[],
to_doc_par_id integer
);
And I have a stored procedure that is meant to accept an array of the following type:
CREATE OR REPLACE FUNCTION insert_law_relations(_items law_relation_update_model[])
RETURNS VOID
AS
$$
BEGIN
END;
$$
LANGUAGE PLPGSQL;
I've removed the body code since it's not relevant cause the following error is thrown at procedure invoke from C#:
malformed array literal
And an inner message of:
array value must start with “{” or dimension information
C# Model that is about to be passed (an array of it):
public class LawRelationUpdateModel
{
public string FromCelex { get; set; }
public string FromArticle { get; set; }
public string ToCelex { get; set; }
public string ToArticle { get; set; }
public IEnumerable<int> LinkIds { get; set; } = new List<int>();
public int ToDocParId { get; set; }
}
And the method that makes the call using Npgsql connector:
public static void InsertLawRelations(LawRelationUpdateModel[] updateModel)
{
using (NpgsqlConnection conn = new NpgsqlConnection(connPG))
{
conn.Open();
NpgsqlCommand comm = new NpgsqlCommand("insert_law_relations", conn);
comm.CommandType = CommandType.StoredProcedure;
var testParam = new NpgsqlParameter();
testParam.DbType = DbType.Object;
testParam.Value = updateModel;
testParam.ParameterName = "_items";
comm.Parameters.Add(testParam);
comm.ExecuteNonQuery();
}
}
Can it be a bug in the connector that somehow does not convert some single/double quotes or brackets correctly when passing?
Or something related to the fact that I asign DBType as an Object? If I don't I get the following error instead:
Can't cast LawRelationUpdateModel[] into any valid DbType.
Any help regarding the issue or other workarounds will be highly appreciated!