Dapper has a “FeatureSupport” class that contains settings for special handling of arrays. Postgresql connections are marked for array support, while other types of connections ( which include MiniProfiler ProfiledDbConnections ) are marked as non-supporting arrays.
If the connection does not support arrays, Dapper manually creates one parameter for each element of the array (as described in the documents) - it becomes a tuple in SQL, for example: SELECT 1 WHERE 42 IN (41, 42,43)
If the connection supports arrays (for example, Postgres' NpgsqlConnection), the parameters of the array are passed directly to the connection, which leads to something ugly: SELECT 1 WHERE 42 IN ( '{41,42,43}' :: int4 [] ) - which not actually executed because IN does not support arrays.
The corresponding code is in the SqlMapper.PackListParameters method.
Therefore, switching between ProfiledDbConnections and NpgsqlConnections is causing problems because the generated SQL will be different.
To get rid of array syntax in Postgres connections, you can use the following code (although it only works on a global level ...):
using Dapper; using Npgsql; using (var cnn = new NpgsqlConnection()) FeatureSupport.Get(cnn).Arrays = false;
There seems to be no way to enable / disable array syntax at the level of each query or at the parameter level.
PS: I found a problem for this problem in https://code.google.com/p/dapper-dot-net/issues/detail?id=107&q=postgres
stmax source share