0
votes

I'm trying to use Dapper to call a PostreSQL function declared as the following:

CREATE OR REPLACE FUNCTION public.test(param1 integer, param2 character varying, param3 character varying)

I'm using Dapper-Async to call this function like this:

cnx.QueryAsync($@"SELECT * FROM public.test(@Param1, @Param2, @Param3);", new { Param1 = 12, Param2 = mylongstring1, Param3 = mylongstring2});

This call fails with the following error:

Npgsql.PostgresException (0x80004005): 42883: function public.test(integer, text, text) does not exist

As you can see, the DbString matches text parameter types. How can I match character varying instead ?

1
@roji This is another issue. I used the same samples. - Olivier MATROT
Apologies - I was too quick, deleted. - Shay Rojansky
Do you want me to open an issue on github ? - Olivier MATROT
For now this looks like a simple parameter type mismatch (see my answer below), if it turns out to be an Npgsql problem then an issue would be good. - Shay Rojansky

1 Answers

0
votes

The issue is probably the fact that your function is defined with parameter type character varying, but as the error shows you're sending text. While this may be somewhat confusing, these are two different backend types.

By default, Npgsql maps .NET string to text, not to character varying. You can either change your function to accept text (or add an overload), or use NpgsqlDbType to specify character varying (not sure how to do this with Dapper though).